Elasticsearch-rails: elasticsearch-model: one index, multiple models, multiple mappings

Created on 16 Apr 2014  路  6Comments  路  Source: elastic/elasticsearch-rails

I have three models and each have their own mappings. All three models are stored in the same index.

If I do

ModelOne.__elasticsearch__.create_index! force: true

then only ModelOne's mappings are returned when I call "GET my_index/_mapping"

Then if I do

ModelTwo.__elasticsearch__.create_index! force: true

then ModelOne's mappings are erased and "GET my_index/_mapping" only return ModelTwo's mappings.

Is there a way to create the index with all the models' mappings? Seems like this should be straightforward, but I am clearly missing something.

question waiting

Most helpful comment

I like the idea of @karmi's IndexManager class because it's testable. I've taken some of those ideas and built a small rake task that calls the index manager. Gist here for anyone that's interested:

https://gist.github.com/nickrivadeneira/e99fbf9beb82fed2f95eaf6964c97853

All 6 comments

If you want to collocate multiple models as types in a single index, you can't use the create_index! method. Collect your mappings with Mymodel.mapping, merge them together, and pass it to indices.create.

Thanks @karmi that worked just fine.

I've created a Rake task and uploaded it to a gist, maybe it's going to be useful for others:

https://gist.github.com/ghilead/6291718b0e97232a09f7

Thanks @ghilead that rake task worked perfectly for me.

Have a look at the IndexManager class in the example application, which merges settings/mappings from multiple models and creates an index.

Thanks @ghilead - the rake task did the trick!

I like the idea of @karmi's IndexManager class because it's testable. I've taken some of those ideas and built a small rake task that calls the index manager. Gist here for anyone that's interested:

https://gist.github.com/nickrivadeneira/e99fbf9beb82fed2f95eaf6964c97853

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nrvakil picture nrvakil  路  3Comments

fatbeard2 picture fatbeard2  路  8Comments

afterclassroom picture afterclassroom  路  7Comments

mcoms picture mcoms  路  4Comments

AaronRustad picture AaronRustad  路  6Comments