ES二次聚合统计桶的个数

ES查询中,运用两次桶查询,第一次根据字段ID聚合,再在每个ID里聚合某一属性的和,请问怎么将第一次聚合的桶的个数写到bucket里面。如下所示情境,应该为一,因为terms过滤只过滤了一个字段。
查询语句如下:
{
    "_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的数量?