# Write and then Read consistency

**URL:** <https://discuss.elastic.co/t/write-and-then-read-consistency/300785>\
**Category:** Elasticsearch\
**Created:** [March 27, 2022, 4:20pm UTC](https://discuss.elastic.co/t/write-and-then-read-consistency/300785 "2022-03-27T16:20:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheGreatBaldOne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thegreatbaldone/32/93645_2.png) [@TheGreatBaldOne](https://discuss.elastic.co/u/TheGreatBaldOne)\
**Post date:** [March 27, 2022, 4:20pm UTC](https://discuss.elastic.co/t/write-and-then-read-consistency/300785/1 "2022-03-27T16:20:00Z")

</div>

I am trying to achieve write and then read consistency.  
In other words, once i update or insert a document, I want to immediately read it correctly.

1. I am getting a a list of a user's posts from ES

2. insert a new post.

3. I would then like to do a 'GetAllPostsByUserId' and also include in that query the previously created postid.

All settings in Elasticsearch are default.

If in step 3, I do the query where I get AllPostsByUserId, and then also include in the filter the  
' **newly created post id**', would Elasticsearch know to get the ' **newly created post id**' from the 'translog'.

====  
For those that do not know, once you write to an index, Elasticsearch only returns once the primary and read-only replicas have also been sync via the translogs, which later gets committed to the index, after 1-2 seconds.

Here is a little trick, is that if you query via a document ID, es will first check translog, and then the index for the document, so you have perfect write-read consistency aslong as you do the 'read' part by including the id.

Mods or whoever may edit my explanation if they like.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 27, 2022, 5:43pm UTC](https://discuss.elastic.co/t/write-and-then-read-consistency/300785/2 "2022-03-27T17:43:02Z")

</div>

This sounds right if your "read" operation is using the [Get API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html) since this API is [realtime by default](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#realtime).

---

<div class="post-metadata">

**Author:** ![TheGreatBaldOne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thegreatbaldone/32/93645_2.png) [@TheGreatBaldOne](https://discuss.elastic.co/u/TheGreatBaldOne)\
**Post date:** [March 29, 2022, 1:11pm UTC](https://discuss.elastic.co/t/write-and-then-read-consistency/300785/3 "2022-03-29T13:11:59Z")

</div>

> **[Multi get (mget) API | Elasticsearch Guide \[8.1\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html)**

Ok so here is the multi get .

---

<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:** [April 26, 2022, 1:12pm UTC](https://discuss.elastic.co/t/write-and-then-read-consistency/300785/4 "2022-04-26T13:12:04Z")

</div>

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