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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -