# \_update\_by\_query is consuming a lot of disk space

**URL:** <https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886>\
**Category:** Elasticsearch\
**Created:** [May 15, 2020, 9:46pm UTC](https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886 "2020-05-15T21:46:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanibash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanibash/32/60905_2.png) [@ivanibash](https://discuss.elastic.co/u/ivanibash)\
**Post date:** [May 15, 2020, 9:46pm UTC](https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886/1 "2020-05-15T21:46:30Z")

</div>

Hi, I created a new field for my indices and running an update\_by\_query where I'm basically populating that field by aggrigating values from other fields:

```
{
  "script": {
    "source": 
      "ctx._source.all_names = []; 
       ctx._source.all_names.add(ctx._source.name); 
       if (ctx._source.previous_names_nested != null) { 
          for (int i=0; i<ctx._source.previous_names_nested.length; i++) {
              ctx._source.all_names.add(ctx._source.previous_names_nested[i].company_name)
           }
       } 
       if (ctx._source.other_names != null) {ctx._source.all_names.addAll(ctx._source.other_names)}"
  }
}

```

While this seems to work, for some reason it's taking WAY more space than expected. Most of the time "previous\_names\_nested" and "other\_names" are null, so only the "name" gets copied. Yet, as I'm running the query and monitoring the disk space, I can see that I will run out of disk space by the time it's finished. Am I doing something wrong here?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 16, 2020, 3:06am UTC](https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886/2 "2020-05-16T03:06:16Z")

</div>

An update is basically a DELETE + an INDEX operation.  
Delete does not really remove the document at first but mark it as deleted (so it consumes more space when you delete a document).

This old non needed space is eventually removed when segments are merged.  
Could you try to run forcemerge API to see if this is better?

If you're updating the whole index, it might be a good idea to actually reindex everything in a new index.

---

<div class="post-metadata">

**Author:** ![ivanibash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanibash/32/60905_2.png) [@ivanibash](https://discuss.elastic.co/u/ivanibash)\
**Post date:** [June 11, 2020, 3:25pm UTC](https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886/3 "2020-06-11T15:25:21Z")

</div>

Thanks for the response, I ran forcemerge, nothing happened straight away but the space got reclaimed overnight. Not sure if forcemerge played part in that or if that happened on its own.

---

<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:** [July 9, 2020, 3:25pm UTC](https://discuss.elastic.co/t/update-by-query-is-consuming-a-lot-of-disk-space/232886/4 "2020-07-09T15:25:25Z")

</div>

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