There're some delay in elasticsearch from requesting to index a document to the document become searchable. I want to know how to deal with this in a unit test, for example, first index a document, then check if it is really indexed. Now I simply use a Thread.sleep() call to delay some time(I'm using a plain junit class), say 2 second. Is this OK? Or there're better solutions?
By default, Elasticsearch periodically refreshes indices every second, but only on indices that have received one search request or more in the last 30 seconds. You can change this default interval using the index. refresh_interval setting.
Why Is ElasticSearch Tuning Required? Elasticsearch gives you moderate performance for search and injection of logs maintaining a balance. But when the service utilization or service count within the infrastructure grows, logs grow in similar proportion.
Windows users can download Elasticsearch as a ZIP file. Simply extract the contents of the ZIP file, and run bin/elasticsearch. bat to start up an instance. Note that you'll need Java installed and configured on your system in order for Elasticsearch to run properly.
You can refresh the indeces after writting to elasticsearch.
By doing,
$ curl -XPOST 'http://localhost:9200/index1,index2/_refresh'
The refresh API allows to explicitly refresh one or more index, making all operations performed since the last refresh available for search. The (near) real-time capabilities depend on the index engine used. For example, the internal one requires refresh to be called, but by default a refresh is scheduled periodically.
See @Elasticsearch website
using java api,
client.admin().indices().prepareRefresh().execute().actionGet()
using the JavaScript client :
client.indices.refresh({index : 'myIndex'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With