11

I am using the Elasticsearch Rails gem and I am using two things in my model:

def as_indexed_json

end

and

settings index: { number_of_shards: 1 } do
  mapping dynamic: 'false' do
    indexes :id
    indexes :customer do                                                                                                                                                                                                                          
      indexes :first_name
    end
  end
end 

I have read the documentation and I am not understanding what the purposes of each of these are. What I am trying to figure out is are these used for searching the indexed data or for creating the indexed data?

Mike Riley
  • 282
  • 3
  • 20

1 Answers1

8

The as_indexed_json method is used to override what data will be send to ES for indexing. How ES is indexing the data you send is configured by the second part.

To search with ES in the indexed data, you have to perform a _query.

Feel free to ask if you need more info

gfd
  • 1,281
  • 1
  • 13
  • 19
  • I have this set up correctly, however I am having trouble with how ES is indexing the data. It is not indexing an associated model. I'll update my code above. I can open a new question if that is better. – Mike Riley Nov 11 '16 at 17:21
  • Have you managed the associated model for ES indexing the same way you did with the first one ? and if so, have you integrated the association in your as_index_json methods ? – gfd Nov 11 '16 at 17:26
  • I have integrated the association in the as_index_json method. I do: self.as_json(include: { customer: { include: { orders: { } }} } – Mike Riley Nov 11 '16 at 19:43
  • Are you saying in my other models (like customer) that I should do the mapping there and not in this same model? So each model should have it's own mapping and be tied together by the as_indexed_json? – Mike Riley Nov 11 '16 at 19:44
  • If you perform queries only on one model (but in the query searching for items that have specific associations), I think you don't need to index your customers separately. But as this is a different question so you might want to post a new question so you'd have more visibility – gfd Nov 12 '16 at 18:06