You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Other than sleep, is there a way to wait until index is ready?
when testing Elasticsearch in rspec, cannot query index after it's created.
# spec/bam.rbrequire'rake'require'elasticsearch/extensions/test/cluster/tasks'require'elasticsearch/persistence/model'classBamincludeElasticsearch::Persistence::ModelendRSpec.describe'Bam'doit'cannot use elasticsearch endpoint after created'doElasticsearch::Persistence.client=Elasticsearch::Client.new(host: 'localhost:9250',log: true)Elasticsearch::Extensions::Test::Cluster.start(nodes: 1)Bam.create_index!(force: true)# neither of the following work# Bam.refresh_index!# Elasticsearch::Persistence.client.indices.refresh# workaround 1 - wait for index to come online# sleep(0.1)# workaround 2 - index a document and wait for it to refresh# bam = Bam.create(id: 'bam')# Bam.refresh_index!# bam.deleteBam.countElasticsearch::Extensions::Test::Cluster.stopendend
@karmi thanks for the suggestion. Neither of Bam.refresh_index! nor Elasticsearch::Persistence.client.indices.refresh works. But sleeping for a bit seems to work.
Activity
karmi commentedon Jun 17, 2015
Sure, just use
refresh_index!(orclient.indices.refreshof course)khoan commentedon Jun 17, 2015
@karmi thanks for the suggestion. Neither of
Bam.refresh_index!norElasticsearch::Persistence.client.indices.refreshworks. But sleeping for a bit seems to work.karmi commentedon Jun 17, 2015
On a really slow system, you might want to wait for cluster health, see eg.
until client.cluster.health(level: 'indices')['indices']['bicycles.stackexchange.com']['status'] == 'green'in https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl#features-overviewkhoan commentedon Jun 17, 2015
that's a more reliable way of checking.
I guess other way is to index a document, call refresh_index!, then delete document.