{ "query": { "bool": { "filter": [{ "range": { "picDate": { "from": "now+8h/d", "to": "now+1d+8h/d" } } },videoReqFilter] } }, "size": 0, "aggs": { "aggs_bucket": { "terms": { "size": 10000, "field": "personId" }, "aggs": { "top_max_hits": { "top_hits": { "sort": [{ "picDate": { "order": "desc" } }], "_source": { "includes": [ "picDate", "indeviceid", "picAddress" ] }, "size": 1 } }, "top_min_hits": { "top_hits": { "sort": [{ "picDate": { "order": "asc" } }], "_source": { "includes": [ "picDate", "indeviceid", "picAddress" ] }, "size": 1 } } } } } }