# NearRealTime aggregation on recent inserted document

**URL:** <https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481>\
**Category:** Elasticsearch\
**Tags:** aggregations\
**Created:** [February 4, 2024, 11:52am UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481 "2024-02-04T11:52:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abduimrn](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@abduimrn](https://discuss.elastic.co/u/abduimrn)\
**Post date:** [February 4, 2024, 11:52am UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/1 "2024-02-04T11:52:20Z")

</div>

Hello,

Elasticsearch is [Near Real Time](https://www.elastic.co/guide/en/elasticsearch/reference/current/near-real-time.html). Which in short it indicates that after issuing an insert request, it will not directly appear to all search and aggregation queries.

In my application I first insert a document then at later stage in execution logic i run an aggregation, I dont see the inserted document result within the aggregated result.

Any suggested solutions ?

---

<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:** [February 4, 2024, 12:32pm UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/2 "2024-02-04T12:32:26Z")

</div>

In order to force new inserts,updates and deletes to appear in search results you cancall the [refresh API](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/indices-refresh.html) before your aggregation. Be aware that this can cause a lot of performance problems if done frequently though as making data available for search is an expensive operation (which is why Elasticsearch is near-real time).

---

<div class="post-metadata">

**Author:** ![abduimrn](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@abduimrn](https://discuss.elastic.co/u/abduimrn)\
**Post date:** [February 4, 2024, 12:41pm UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/3 "2024-02-04T12:41:52Z")

</div>

**Thanks for answering.**

I missed that in my original question, I have tried it and i know its drawbacks.

I am still looking for alternative solutions if they exist.

---

<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:** [February 4, 2024, 12:49pm UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/4 "2024-02-04T12:49:10Z")

</div>

For the documents to be searchable a refresh have to occur, so there are no alternatives. You could force a refresh at indexing time, which would remove the need for a separate API call, but that would likely have an even bigger negative impact on performance.

---

<div class="post-metadata">

**Author:** ![abduimrn](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@abduimrn](https://discuss.elastic.co/u/abduimrn)\
**Post date:** [February 5, 2024, 5:20am UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/5 "2024-02-05T05:20:50Z")

</div>

I see, thanks alot

---

<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:** [March 4, 2024, 5:21am UTC](https://discuss.elastic.co/t/nearrealtime-aggregation-on-recent-inserted-document/352481/6 "2024-03-04T05:21:12Z")

</div>

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