I am using elasticsearch 5.3 and trying to receive min/max/avg aggregations by date.
curl -XPOST localhost:9200/avtostat/ads/_search -d
{
"size":0,
"aggs":{
"prices_per_month":{
"date_histogram":{
"field":"state_date",
"interval":"week"
},
"aggs":{
"prices":{
"sum":{
"field":"price_usd"
}
}
}
},
"avg_monthly_prices":{
"avg_bucket":{
"buckets_path":"prices_per_month>prices"
}
}
}
}
It returns next data:
{
"took":12,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"failed":0
},
"hits":{
"total":38627,
"max_score":0.0,
"hits":[
]
},
"aggregations":{
"prices_per_month":{
"buckets":[
{
"key_as_string":"2017-01-02",
"key":1483315200000,
"doc_count":11918,
"prices":{
"value":5.6471833E7
}
},
{
"key_as_string":"2017-01-09",
"key":1483920000000,
"doc_count":0,
"prices":{
"value":0.0
}
},
{
"key_as_string":"2017-01-16",
"key":1484524800000,
"doc_count":6322,
"prices":{
"value":3.0116144E7
}
},
{
"key_as_string":"2017-01-23",
"key":1485129600000,
"doc_count":20386,
"prices":{
"value":9.3860144E7
}
},
{
"key_as_string":"2017-01-30",
"key":1485734400000,
"doc_count":1,
"prices":{
"value":2900.0
}
}
]
},
"avg_monthly_prices":{
"value":4.511275525E7
}
}
}
It returns aggregation for one month only, but i have data for february and march. How to get it.
More info here https://stackoverflow.com/questions/43227101/elasticsearch-date-histogram-aggregations-with-min-max-avg