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.
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.
The text was updated successfully, but these errors were encountered: