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.
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:
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
Most helpful comment
I like the idea of @karmi's
IndexManagerclass 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