# \_update\_by\_query for non-refreshed documents

**URL:** <https://discuss.elastic.co/t/update-by-query-for-non-refreshed-documents/305210>\
**Category:** Elasticsearch\
**Created:** [May 19, 2022, 4:11pm UTC](https://discuss.elastic.co/t/update-by-query-for-non-refreshed-documents/305210 "2022-05-19T16:11:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grzyboo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@grzyboo](https://discuss.elastic.co/u/grzyboo)\
**Post date:** [May 19, 2022, 4:11pm UTC](https://discuss.elastic.co/t/update-by-query-for-non-refreshed-documents/305210/1 "2022-05-19T16:11:52Z")

</div>

Hi!  
I have an index **products**. What I need is to update **categoryDisplayName** for all products with given **categoryName**. Whenever my application gets an event to update categoryName the app saves it and fills it into newly created product documents, so new products always have up-to-date categoryName. Such event should also trigger categoryName update for products already existing in the elastic index.

For this purpose I've used _update by query_. However I struggle with keeping the consistency of my data, because when _update by query_ is used, there is a time window in which some recently created documents might not be refreshed yet (and won't be queried by my update\_by\_query request).

The problem is - even though my application received "Change Category Name" event and had already saved a product, if this particular product happens to be in the unlucky time window its document will simply have wrong data, its category will never be updated.

How to deal with it? Should I refresh right before doing update\_by\_query? It can also lead to a (much smaller) time window between \_refresh request and \_update\_by\_query request. Or is there any other way to deal with such inconsistencies?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 19, 2022, 11:49pm UTC](https://discuss.elastic.co/t/update-by-query-for-non-refreshed-documents/305210/2 "2022-05-19T23:49:38Z")

</div>

Welcome to our community! 😃

> [@grzyboo](#):
>
> Should I refresh right before doing update\_by\_query?

That's probably the best option.

---

<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:** [June 16, 2022, 11:50pm UTC](https://discuss.elastic.co/t/update-by-query-for-non-refreshed-documents/305210/3 "2022-06-16T23:50:20Z")

</div>

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