# How to get aggregation bucket of certain field values use as a key

**URL:** <https://discuss.elastic.co/t/how-to-get-aggregation-bucket-of-certain-field-values-use-as-a-key/314829>\
**Category:** Elasticsearch\
**Created:** [September 21, 2022, 6:10am UTC](https://discuss.elastic.co/t/how-to-get-aggregation-bucket-of-certain-field-values-use-as-a-key/314829 "2022-09-21T06:10:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuvraj.singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuvraj.singh/32/111064_2.png) [@yuvraj.singh](https://discuss.elastic.co/u/yuvraj.singh)\
**Post date:** [September 21, 2022, 6:10am UTC](https://discuss.elastic.co/t/how-to-get-aggregation-bucket-of-certain-field-values-use-as-a-key/314829/1 "2022-09-21T06:10:09Z")

</div>

\</\>let suppose , I have some data like\</\>

`document 1 :`

```auto
 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "HP"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}

```

`document 2 :`

```auto
 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "Samsung"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}
}

```

`document 3 :`

```auto
 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "Asus"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}
}

```

`now i want my buckets be like :`

```auto
"aggregations": {
        "brands": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "HP",
                    "doc_count": 1
                },
                {
                    "key": "Samsung",
                    "doc_count": 1
                },
                {
                    "key": "Asus",
                    "doc_count": 1
                }
                ]
        }
}

```

`How do i do it ?`

---

<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:** [October 19, 2022, 6:10am UTC](https://discuss.elastic.co/t/how-to-get-aggregation-bucket-of-certain-field-values-use-as-a-key/314829/2 "2022-10-19T06:10:29Z")

</div>

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