# Using the UpdateByQuery with InlineScript,100000+ items it is giving the max timeout exception

**URL:** <https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434>\
**Category:** Elasticsearch\
**Created:** [March 5, 2025, 7:52am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434 "2025-03-05T07:52:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rutuja](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@rutuja](https://discuss.elastic.co/u/rutuja)\
**Post date:** [March 5, 2025, 7:52am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/1 "2025-03-05T07:52:34Z")

</div>

I am using the UpdateByQuery with InlineScript, but it is working for only 30000-40000 items while updating, and for 100000+ items it is giving the connection time out exception and only updating 14000 items.  
i want to work with update query with Inline scripting for large data, but UpdateQuery is not working with large data as 100000+ documents to update.  
Also tried the timeout field of request and gave the 20 minutes, and wait for completion flag=true, still not worked.

Please provide some solution!

---

<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:** [March 5, 2025, 12:35pm UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/2 "2025-03-05T12:35:31Z")

</div>

Which version of Elasticsearch are you using?

How many nodes do you have in the cluster?

What is the hardware specification of the nodes in the cluster, e.g. CPU, RAM and type and size of storage used?

What is the shard size and count of the indices you are updating, both in terms of document count and size on disk?

What is the average size of the documents you are updating?

Do the documents you are updating use nested mappings or join fields?

What other load, if any, is the cluster under when you perform this operation?

---

<div class="post-metadata">

**Author:** ![rutuja](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@rutuja](https://discuss.elastic.co/u/rutuja)\
**Post date:** [March 6, 2025, 7:36am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/3 "2025-03-06T07:36:19Z")

</div>

Elastic version : 7.17.9  
nodes in cluster : 1  
CPU:  
RAM:32GB  
assigned heap max size:8  
shard size:  
shard count:18  
average size of the documents need to update: 200000+ to even more  
yes nested property present

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/b/3b8b98f8adee66a96a1c2ce42dcad3130bb63fd3.png)

---

<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:** [March 6, 2025, 7:43am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/4 "2025-03-06T07:43:30Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> What is the hardware specification of the nodes in the cluster, e.g. CPU, RAM and type and size of storage used?

What type of storage are you using?

> [@Christian\_Dahlqvist](#):
>
> What is the average size of the documents you are updating?

> [@rutuja](#):
>
> yes nested property present

I asked about the average size of the documents (kB), not the count. As you are using nested mappings, how many nested documents are there on average per document?

---

<div class="post-metadata">

**Author:** ![rutuja](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@rutuja](https://discuss.elastic.co/u/rutuja)\
**Post date:** [March 6, 2025, 8:36am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/5 "2025-03-06T08:36:56Z")

</div>

Storage: SSD (c drive), space(total-476GB, free-103 GB)  
average size of documents: 87100kb

---

<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:** [March 6, 2025, 9:03am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/6 "2025-03-06T09:03:51Z")

</div>

> [@rutuja](#):
>
> average size of documents: 87100kb

Is the average document size really 87MB?

How many nested documents does such a large document contain on average?

Note that updating vary large documents with large number of nested documents results in a lot of overhead as the full document need to be reindexed. Each nested document is behind the scenes stored as a separate document, which also adds to the overhead.

If the numbers are correct and that is your average document size I would recommend you revise how you index and manage your data.

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [March 6, 2025, 9:20am UTC](https://discuss.elastic.co/t/using-the-updatebyquery-with-inlinescript-100000-items-it-is-giving-the-max-timeout-exception/375434/7 "2025-03-06T09:20:53Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> Is the average document size really 87MB?

must be a typo, 87MB per doc, update 100k of them at a time, doesn't fit on a 476GB disk.

> [@Christian\_Dahlqvist](#):
>
> I would recommend you revise how you index and manage your data.

Seems so.

@rutuja Can you outline a little your use case here? This seems an unusual way of maintaining data in elasticsearch. What (in. general terms) is the data, why does it require updating after indexing, why you need to update so many docs at once, ... Maybe if we understood the use case better, another idea might present itself.
