使用kibana索引:kibana_sample_data_ecommerce
GET kibana_sample_data_ecommerce/_search
{
"track_total_hits": true,
"size": 0,
"aggs": {
"terms_day_of_week": {
"terms": {
"field": "day_of_week",
"size": 1000,
"include": ["Monday","Tuesday"]
}
}
}
}
运行结果
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4675,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"terms_day_of_week" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Tuesday",
"doc_count" : 609
},
{
"key" : "Monday",
"doc_count" : 579
}
]
}
}
}
请问怎么求609和579的差是多少? 可以用es直接计算出来吗
感谢评论区大神的回复:
GET kibana_sample_data_ecommerce/_search
{
"track_total_hits": true,
"size": 0,
"aggs": {
"top": {
"terms": {
"script": "true"
},
"aggs": {
"terms_day_of_week": {
"filter": {
"term": {
"day_of_week": "Monday"
}
}
},
"terms_day_of_week2": {
"filter": {
"term": {
"day_of_week": "Tuesday"
}
}
},
"difference": {
"bucket_script": {
"buckets_path": {
"p1": "terms_day_of_week._count",
"p2": "terms_day_of_week2._count"
},
"script": "params.p1 - params.p2"
}
}
}
}
}
}