主要知识点:
- data_historgram之后再进行下钻分析。
语法:
GET /tvs/sales/_search
{
"size": 0,
"aggs": {
"group_by_sold_date": {
"date_histogram": {
"field": "sold_date",
"interval": "quarter",
"format": "yyyy-MM-dd",
"min_doc_count": 1,
"extended_bounds": {
"min": "2016-01-01",
"max": "2017-12-31"
}
},
"aggs": {
"group_by_brand": {
"terms": {"field": "brand"},
"aggs": {"sum_price": {"sum": {"field": "price"}}}
},
"total_sum_price": {"sum": {"field": "price"}}
}
}
}
}
执行结果:
"aggregations": {
"sales": {
"buckets": [
{
"key_as_string": "2016-05-01",
"key": 1462060800000,
"doc_count": 1,
"totol_brand_price": {
"value": 3000
},
"group_by_brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "小米",
"doc_count": 1,
"sum_price": {
"value": 3000
}
}
]
}
}