Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with elasticsearch delay when doing unit test?

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?

like image 505
D_S_toowhite Avatar asked Aug 13 '14 03:08

D_S_toowhite


People also ask

How do I change the refresh interval in Elasticsearch?

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.

What is the need for tuning the performance of Elasticsearch?

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.

How do you test elastic search?

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.


1 Answers

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'});
like image 134
progrrammer Avatar answered Sep 20 '22 06:09

progrrammer