0
votes

How do I index a specific field on an embedded document using the tire gem for ElasticSearch's syntax?

I have tried the following for my Question model which embeds many Answers and I would like only the description field on the Answer model to be indexed.

Searching for text that should match a stored answer's description is returning no results. I am using Mongoid as my MongoDB driver by the way.

 mapping do
    indexes :id, :index => :no
    indexes :created_at, :index => :no
    indexes :updated_at, :index => :no
    indexes :title, :index => :analyzed
    indexes :description, :index => :analyzed
    indexes :page_views, :index => :no
    indexes :asker, :index => :no
    indexes :tags, :index => :analyzed
    indexes :answers do
      indexes :id, :index => :no
      indexes :description, :index => :analyzed
      indexes :answerer, :index => :no
      indexes :created_at, :index => :no
      indexes :updated_at, :index => :no
    end
    indexes :comments, :index => :no
    indexes :votes, :index => :no
    indexes :up_count, :index => :no
    indexes :down_count, :index => :no
    indexes :vote_score, :index => :no
  end
1
Did my answer help in anyway? If you have any comments please ask away!ramseykhalaf

1 Answers

1
votes

I think you need to specify the type of each field before you can set the "index" parameter. (I might be wrong)

I think this will not work:

"properties": {
  "description": {
    "index": "analyzed"
  }
}

Try this instead:

"properties": {
  "description": {
    "type": "string",
    "index": "analyzed" //not really needed as the default is analyzed
  }
}

Can you please check your mapping by using:

curl -XGET 'http://localhost:9200/your_index/your_type/_mapping'

Post the output and we will see if elasticsearch is configured correctly.

Good luck!