# Update counter by bucket?

**URL:** <https://discuss.elastic.co/t/update-counter-by-bucket/190596>\
**Category:** Elasticsearch\
**Created:** [July 15, 2019, 6:17pm UTC](https://discuss.elastic.co/t/update-counter-by-bucket/190596 "2019-07-15T18:17:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yobrohowitgo](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@yobrohowitgo](https://discuss.elastic.co/u/yobrohowitgo)\
**Post date:** [July 15, 2019, 6:17pm UTC](https://discuss.elastic.co/t/update-counter-by-bucket/190596/1 "2019-07-15T18:17:53Z")

</div>

I have an agg query that combines documents with the same email in buckets. I am trying to implement a counter that increments an ID by bucket - but the records within each bucket should have the same ID. I have seen the update API documentation but that doesnt address bucket updates.

[https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docs-update-by-query.html)

please see query below

```auto
POST /my_index/_search? 
{ 
    "size": 0, 
    "aggs": { 
        "GroupByType": { 
            "terms": { 
                "field": "Email.keyword", 
                "size": 15 
            }, 
            "aggs": { 
                "Group": { 
                    "top_hits": { 
                        "size": 2, 
                        "_source": { 
                            "includes": [ 
                                "Email", 
                                "CustomerNo", 
                                "FirstName", 
                                "LastName", 
                                "Phone" 
                            ] 
                        }, 
                        "sort": [ 
                            { 
                                "CustomerNo.keyword": { 
                                    "order": "asc" 
                                } 
                            } 
                        ] 
                    } 
                } 
            } 
        } 
    } 
}

```

---

<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 12, 2019, 6:28pm UTC](https://discuss.elastic.co/t/update-counter-by-bucket/190596/2 "2019-08-12T18:28:40Z")

</div>

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