# Does update and query document in diff cache?

**URL:** <https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014>\
**Category:** Elasticsearch\
**Created:** [November 16, 2022, 3:54am UTC](https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014 "2022-11-16T03:54:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GithubRyze](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GithubRyze](https://discuss.elastic.co/u/GithubRyze)\
**Post date:** [November 16, 2022, 3:54am UTC](https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014/1 "2022-11-16T03:54:55Z")

</div>

step:

1. updated document
2. query the document immediately

expected:  
return latest of the document

but  
retunr the old docment

Does update and query document in diff cache? update in RAM CACHE and QUERY IN DISK ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 16, 2022, 6:12am UTC](https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014/2 "2022-11-16T06:12:45Z")

</div>

This is expected and has nothing to do with caching. When a document is indexed it is written to the transaction log. At this point it is safely stored but not yet searchable. Elasticsearch stores searchable data in immutable segments, and as these are relatively expensive to create, so for performance reasons they are only generated periodically based on data in the transaction log. By default this happens once per second, which is why the data does not immediately show up in searches. You can read more about this [here](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/near-real-time.html).

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [November 16, 2022, 6:17am UTC](https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014/3 "2022-11-16T06:17:16Z")

</div>

What @Christian_Dahlqvist is describing is absolutely correct for `_search` you _ **can** _ immediately `read` the document by `_id` as soon as as the index operation is finished.

`GET my-index/_doc/<document _id>`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 14, 2022, 6:17am UTC](https://discuss.elastic.co/t/does-update-and-query-document-in-diff-cache/319014/4 "2022-12-14T06:17:17Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
