jquery - Elasticsearch Query - How to aggregate timestamps and filter by term? -
i have working filter query:
{ "filter": { "and": [{ "range": { "timestamp": { "gte": "2015-05-07t12:04:30z" "lte": "2015-08-07t12:04:30z" } } }, { "term": { "in_context.course_id": "1234567" } }] }, "fields": ["timestamp"] }
which returns timestamp of every event in last 3 months. there ~ 1 million timestamps returned makes response large, aggregate results , sum of documents per day.
i found snippet uses date histogram:
{ "aggs" : { "histo1" : { "date_histogram" : { "field" : "timestamp", "interval" : "day" }, "aggs" : { "price_stats" : { "stats" : { "field" : "price" } } } } } }
which need, can't figure out how incorporate original query term filter! glad help!
you can adding aggs
part @ top level in query. note wrapped filter
filtered
query.
{ "size": 0, "query": { "filtered": { "filter": { "and": [ { "range": { "timestamp": { "gte": "2015-05-07t12:04:30z", "lte": "2015-08-07t12:04:30z" } } }, { "term": { "in_context.course_id": "1234567" } } ] } } }, "aggs": { "histo1": { "date_histogram": { "field": "timestamp", "interval": "day" } } } }
Comments
Post a Comment