# Using Aggregation by range time and terms

**URL:** <https://discuss.elastic.co/t/using-aggregation-by-range-time-and-terms/61992>\
**Category:** Elasticsearch\
**Created:** [October 1, 2016, 9:05pm UTC](https://discuss.elastic.co/t/using-aggregation-by-range-time-and-terms/61992 "2016-10-01T21:05:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tenaz3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenaz3/32/5648_2.png) [@tenaz3](https://discuss.elastic.co/u/tenaz3)\
**Post date:** [October 1, 2016, 9:05pm UTC](https://discuss.elastic.co/t/using-aggregation-by-range-time-and-terms/61992/1 "2016-10-01T21:05:10Z")

</div>

Hi, I quite new on this concept of aggregations so still with basic problems to understand  
I wanna 7 results of top events for the next 2 months. So I have two attributes to look. The max of people attending(attendings) is the definition of Top, but also I wanna order this by time(start\_time: asc)  
What I start to wrote but is wrong:

```
{
        "aggs": {
            "aggs": {
                "event_interval": {
                    "date_histogram": {
                        "field": "start_time",
                        "interval": "2M",
                        "format": "dateOptionalTime"
                    }
                },
                "max_attending": { "max": { "field": "attending" } },
                "_source": {
                    "include": [
                        "name"
                    ]
                }
            }
        }
    }
```

---

<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 5, 2017, 10:15pm UTC](https://discuss.elastic.co/t/using-aggregation-by-range-time-and-terms/61992/2 "2017-07-05T22:15:34Z")

</div>


