简体   繁体   中英

Are ElasticSearch query results cached?

I'm using ElasticSearch 2.3 and ASP.NET web application. I'm calling ElasticSearch through its REST API using C# HttpClient .

I have a problem when trying to add new values to an array.

Here's essentially the queries that I'm performing:

Step 1: Get note

POST /notes/note/_search
{
  "query" : {
    "term" : { "_id" : 1 }
  }
}

There's only 1 note and the result shows that the note contains an empty array of attachments

Step2: Update note attachments array

POST: /notes/note/1/_update
{
   "doc" : { 
      "Attachments" : [ "Test" ]
   }
}

Step3: Get note again

POST: /notes/note/_search
{
  "query" : {
    "term" : { "_id" : 1 }
  }
}

The result shows that the note still contains an empty Attachments array .

However, when I Search/MatchAll from Kibana, I see that the Attachments array has been updated with the new item. However, when running all those steps from ASP.NET, I'm not getting the updated document when immediately searching for it right after the update.

Is this caused by some kind of caching ?

What must I do to get consistent state of the document after an update has been performed ?

Any help appreciated! Thanks

What could be happening is that the refresh did not come by yet. Than you are able to do a get by id, but the update is not available yet for search. So force a refresh before executing the search. When inserting a lot of documents this does have a performance impact. But for testing you should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM