Bick
Bick

Reputation: 18521

ElasticSearch cluster behavior - Define all nodes to update together

After I insert a document to ElasticSearch I immediately go and retrieve it with a query. I am polling the request several times so if it isn't completely indexed it will return in the second or third try.

Sometimes, in a clustered environment, I have noticed that I can get the request and a milisecond later the same request is returned empty.

I assume that it goes to another node in the cluster - that is not yet indexed.

If this is it, I really need to define the cluster to return a value only after all nodes are updated with it.

  1. Was what I described true? Is it possible that not all nodes are updated together?
  2. Is it a cluster configuration issue ? Is it solvable with configuration?

Thanks.

Upvotes: 1

Views: 54

Answers (1)

Val
Val

Reputation: 217274

What you're experiencing is normal given Elasticsearch works in "near-real" time. By default, the cluster is refreshed every second, but you can change that in the configuration if you need to perform refreshes more often. Doing so you run the risk of putting your cluster under a heavy load.

An alternative way if you want the result of your indexing operation to be available for the next call, is to explicitly refresh your cluster and only then issue a search request.

  1. index your document PUT /my_index/doc/1
  2. call refresh POST /my_index/_refresh
  3. send your request POST /my_index/_search

Upvotes: 1

Related Questions