# Is Update By Query API a good choice to update single document in elasticsearch?

**URL:** <https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035>\
**Category:** Elasticsearch\
**Created:** [September 1, 2021, 11:28am UTC](https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035 "2021-09-01T11:28:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthikeyan\_Amaresan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthikeyan_amaresan/32/94017_2.png) [@Karthikeyan\_Amaresan](https://discuss.elastic.co/u/Karthikeyan_Amaresan)\
**Post date:** [September 1, 2021, 11:28am UTC](https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035/1 "2021-09-01T11:28:39Z")

</div>

I have a use case where i want to update the document without knowing its index. Currently i am querying by id and getting the index and then updating (2 operation). Update By Query API seems to perform this use case in single operation. But i am just skeptical because as per the elasticsearch documentation,

```auto
When you submit an update by query request, Elasticsearch gets a snapshot of the data stream or index when it begins processing the request and updates matching documents using internal versioning.

```

As there will be a lot of updates individually, just want to know whether there will be a performance overhead when using \_update\_by\_query for updating single document than getting and update using \_update api.

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 1, 2021, 11:33am UTC](https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035/2 "2021-09-01T11:33:49Z")

</div>

Update-by-query uses [scrolled searches](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/scroll-api.html), which in turn use a point in time snapshot of the data - however this won't be held to long in your case as you only update a single document.

I do not have any numbers in this concrete use-case what will save more resources, so it really is hard to tell from my point of view.

About how many updates per time frame are you talking?

---

<div class="post-metadata">

**Author:** ![Karthikeyan\_Amaresan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthikeyan_amaresan/32/94017_2.png) [@Karthikeyan\_Amaresan](https://discuss.elastic.co/u/Karthikeyan_Amaresan)\
**Post date:** [September 1, 2021, 1:30pm UTC](https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035/3 "2021-09-01T13:30:16Z")

</div>

Thank for the reply @spinscale . Currently we are having 600 updates every minute on average. But the numbers can scale if the consumption scales, which is very likely. Now that you have mentioned, its scrolled search that is behind the scene, also just curious if there is a chance for max\_open\_scroll\_context to exceed max limit which is 500 by default, if we use \_update\_by\_query.

---

<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:** [September 29, 2021, 1:30pm UTC](https://discuss.elastic.co/t/is-update-by-query-api-a-good-choice-to-update-single-document-in-elasticsearch/283035/4 "2021-09-29T13:30:58Z")

</div>

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