{
"_source": ["txCode", "tyTotal", "tyCnt1"],
"query": {
"bool": {
"filter": [{
"range": {
"tjrq": {
"gte": "2022-10-09",
"time_zone": "+08:00",
"lte": "2022-11-08"
}
}
}, {
"terms": {
"bmbh": [510116006000]
}
}]
}
},
"aggs": {
"txCode": {
"terms": {
"size": 2000,
"field": "bmbh"
},
"aggs": {
"tyTotal": {
"sum": {
"field": "jqzs"
}
},
"tyCnt1": {
"sum": {
"field": "jqyfps"
}
}
}
}
}
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 0,
"hits": [
{
"_index": "tab_zfjd_dataanalysis_jq_1",
"_type": "_doc",
"_id": "5101160060002022-11-01",
"_score": 0,
"_source": {}
},
{
"_index": "tab_zfjd_dataanalysis_jq_1",
"_type": "_doc",
"_id": "5101160060002022-11-03",
"_score": 0,
"_source": {}
}
]
},
"aggregations": {
"txCode": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "510116006000",
"doc_count": 2,
"tyCnt1": {
"value": 2
},
"tyTotal": {
"value": 8
}
}
]
}
}
}
尝试过写到aggs里,value_count {field:_index},但是实际上是第二层内聚的条数,并不是bucket的个数。
可见bucket里面已经有了source里的字段,但是如何对bucket个数进行计数并塞进这个bucket里面呢,这里如何在bucket里面添加一个total变量,为bucket的数量?