# About bucket aggregation

**URL:** <https://discuss.elastic.co/t/about-bucket-aggregation/175186>\
**Category:** Elasticsearch\
**Created:** [April 3, 2019, 12:03pm UTC](https://discuss.elastic.co/t/about-bucket-aggregation/175186 "2019-04-03T12:03:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![med\_barka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/med_barka/32/45131_2.png) [@med\_barka](https://discuss.elastic.co/u/med_barka)\
**Post date:** [April 3, 2019, 12:03pm UTC](https://discuss.elastic.co/t/about-bucket-aggregation/175186/1 "2019-04-03T12:03:39Z")

</div>

hello, i want to bucket my documents according to a change of a field  
e.g : i have 3 fields : timestamp, name, switch (boolean field that i want to change bucket accordingly to it) and data :  
2019-02-08T07:06:01.106Z |name1 |0  
2019-02-08T08:06:01.106Z| name2 | 0  
2019-02-08T09:06:01.106Z| name3| 1  
2019-02-08T10:06:01.106Z| name4| 0  
2019-02-08T10:06:01.106Z| name5| 0

So the results would be 3 bucket :  
bucket1 having docs(name1,name2),  
bucket 2 having docs(name3),  
bucket 3 having docs(name4,name5)  
Can this be done ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![med\_barka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/med_barka/32/45131_2.png) [@med\_barka](https://discuss.elastic.co/u/med_barka)\
**Post date:** [April 4, 2019, 4:07pm UTC](https://discuss.elastic.co/t/about-bucket-aggregation/175186/2 "2019-04-04T16:07:54Z")

</div>

any idea please? i tried this one but it gives only two bucket with 0 and 1

```
GET idx_name/_search
{
  "size": 0, 
    "query": {
      "bool": {
        "filter": {
          "term": { "allData.uid" : "12121" } }
        }}
    ,"sort": { "@timestamp": {"order": "asc" }}
     ,"aggs": {
           "switch":
                {"terms": {"field": "allData.switch"}}
           }
}
```

---

<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:** [May 2, 2019, 4:07pm UTC](https://discuss.elastic.co/t/about-bucket-aggregation/175186/3 "2019-05-02T16:07:58Z")

</div>

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