# Order by peak value for a time-interval(like 5m) in terms aggregation

**URL:** <https://discuss.elastic.co/t/order-by-peak-value-for-a-time-interval-like-5m-in-terms-aggregation/94108>\
**Category:** Elasticsearch\
**Created:** [July 21, 2017, 11:47am UTC](https://discuss.elastic.co/t/order-by-peak-value-for-a-time-interval-like-5m-in-terms-aggregation/94108 "2017-07-21T11:47:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![junkainiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/junkainiu/32/23928_2.png) [@junkainiu](https://discuss.elastic.co/u/junkainiu)\
**Post date:** [July 21, 2017, 11:47am UTC](https://discuss.elastic.co/t/order-by-peak-value-for-a-time-interval-like-5m-in-terms-aggregation/94108/1 "2017-07-21T11:47:10Z")

</div>

HI,  
I am using elasticsearch 5.3 and need to calculate top 50 client\_ip and order by **1m-peak-value** in one day .  
like this , I try to use a 1 size date\_histogram to get the peak value,

```auto
"aggs": {
          "client_ip": {
            "terms": {
              "field": "ClientIp", 
              "order": {"timeline>pktlen": "desc"},
              "size": 50
            },
            "aggs": {
              "timeline": {
            	"date_histogram": {
            		"field": "ts",
            		"interval": "1m",
            		"order": {"pktlen": "desc"},
                    "size": 1
            	},
            	"aggs": {
            		"pktlen": {
                		"sum": {
                			"field": "PktLen_Sum"
                		}
            		}
            	}
              }
          }
        }
      }

```

Sadly, it gets two errors

- Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end

- Date histogram not support size

So how can I get the top 50 client\_ip ordered by peak value

---

<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 18, 2017, 11:47am UTC](https://discuss.elastic.co/t/order-by-peak-value-for-a-time-interval-like-5m-in-terms-aggregation/94108/2 "2017-08-18T11:47:14Z")

</div>

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