0

I'm using ES to retrieve data, which I change and update back in ES followed by doing the same search query - it looks like I don't always get the updated document back down and have to wait a second or two.

Using the following code:

esClient.Update<TESDocModel, TESDocModel>(new DocumentPath<TESDocModel>(docId), u => u.Index(index).Doc(toUpdate).DocAsUpsert(true));

Is this correct behaviour or should a document be immediately searchable after the upsertdocument operation is complete?

meds
  • 21,699
  • 37
  • 163
  • 314
  • 1
    this answer may help: https://stackoverflow.com/questions/42406674/elastic-search-get-doesnt-give-latest-document/42407323#42407323 – Val Mar 25 '19 at 05:01

1 Answers1

2

This depends on when refresh action on the shard is performed. When a document is indexed it is not searchable immediately. To make is searchable refresh action on a shard is performed. This behind the scenes writes and opens a new segment making the documents that are contained in those segments to be searchable.

By default elastic refreshes shard every second. This is why it is said that Elasticsearch has near real-time search.

The refresh interval can be controlled by index setting param refresh_interval. For e.g the below will change the refresh interval to 5 seconds and any new document indexed will at max take 5 secs to be searchable.

PUT /my_index
{
  "settings": {
    "refresh_interval": "5s" 
  }
}

To understand more on it read about elasticsearch near real time search.

Nishant
  • 7,504
  • 1
  • 21
  • 34
  • I completely agree with Nishant Saini, by 'refresh_interval' it should solve your problem at some level, but the indexing also takes some time to make the document indexed. you can check the same by uploading very small size document and by uploading somewhat big size document. – Riddhi Makwana Mar 25 '19 at 05:51