Index mapping is intermittently not working for Tire::Persistence model #689

radixhound opened this Issue Mar 29, 2013 · 3 comments


None yet

2 participants


We have created a Tire::Persistence model to store our data in ES. Initially we made the mistake of not using :not_analyzed for our regions which are strings like "US Hawaii" and thus the facets didn't work properly because they were being broken out into words.

We finally discovered that we had to set them as not_analyzed and we did basically this:

class IndexedThing
  include Tire::Model::Persistence

  mapping { indexes :region, index: :not_analyzed }

  property :region, index: :not_analyzed

This worked. Then we changed some more things, dropped and rebuilt the index and it stopped working. After some dropping and rebuilding it was working again. Currently it is not working and yesterday I spent a couple of hours trying to reproduce steps to get it to consistently fail so I could resolve it. No dice!

This is highly frustrating. I have tried looking into gem dependencies, such as multi_json and thought that it was the cause, but in the end, I could not consistently reproduce with and without.

I'm hoping that you can offer a suggestion as to why this would happen?

We are dropping and creating the index basically thus:

IndexedThing.create {id: 1, region: "US Hawaii"}

then we check the mapping and we see something like this

=> {"indexed_thing"=>{"properties"=>{"region"=>{"type"=>"string"}}}}

but when it is working we see

{"indexed_thing"=>{"properties"=>{"region"=>{"type"=>"string", "index"=>"not_analyzed"}}}}

Is there a way, perhaps to explicity drop the mapping and rebuild it manually?


Hi, the reason why you're seeing inconsistent behaviour is because a) you're not creating the index explicitely, b) it all depends on whether you restart/reload your application/code, or not. Tire by default tries to create an index for the model with proper mappings/settings, when you start the application, and the index does not yet exists.

So, in your workflow, the correct sequence would be something like:

IndexedThing.create {id: 1, region: "US Hawaii"}

The create_elasticsearch_index effectively does IndexedThing.tire.index.create(mappings: IndexedThing.tire.mapping_to_hash, settings: IndexedThing.tire.settings). Notice that the rake tire:import:model Rake task also allows you to re-create the index.


Notice that the rake tire:import:model Rake task

Sorry, missed this is about Tire::Model::Persistence. Still, IndexedThing.tire.create_elasticsearch_index is the way to go.


So helpful. Thank you!

@radixhound radixhound closed this Apr 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment