# Is there a way to update by Aggregation results

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-update-by-aggregation-results/242617>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 25, 2020, 8:13pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-update-by-aggregation-results/242617 "2020-07-25T20:13:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WoH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woh/32/48707_2.png) [@WoH](https://discuss.elastic.co/u/WoH)\
**Post date:** [July 25, 2020, 8:13pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-update-by-aggregation-results/242617/1 "2020-07-25T20:13:04Z")

</div>

I'm looking to update a large amount of documents. I am able to update individual documents if I use the following script where MD51 and MD52 are the actual values that I enter.

```auto
    {
      "script": {
        "source": "ctx._source.isDupe = \"true\"",
        "lang": "painless"
      },
      "query": {
        "terms": {
        "MD5.keyword":["MD51","MD52"]
    }}}

```

I'd like to know if there's a way to do this from the results of an aggregation and update them all at once.

```auto
    POST testsizeindex/_update_by_query
    {
      "script": {
        "source": "ctx._source.isDupe = \"true\"",
        "lang": "painless"
      },
        "aggs": {
        "2": {
          "terms": {
            "field": "MD5_hash.keyword",
            "min_doc_count": 2
            }
          }
        }
      }

```

---

<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:** [August 22, 2020, 8:13pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-update-by-aggregation-results/242617/2 "2020-08-22T20:13:05Z")

</div>

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