Search code examples
ruby-on-railsrubyelasticsearchtire

Ruby-Tire wait for indexes to get created


Using Tire I need to fill indexes in the test cases after I create some records, which I do like this.

['London', 'Mumbai', 'New York'].each { |name| Place.create(name: name) }
t = Tire.index('places')
t.import(Place.all.entries)

How do I wait for the index to be created before proceeding?


Solution

  • Call t.refresh directly after you call import. This will ensure that Tire is in sync with elasticsearch.