我有评论,每条评论都链接到一个媒体资源。因此,对于一个物业ID,可能会有多个评论,这些评论也可以重复。 现在,我需要获取每个属性的重复评论总数。
这是我如何获得每个物业的重复评价
"query": {
"bool": {
"must_not": [
{
"term": {
"reviewKeyword": {
"value": ""
}
}
}
]
}
},
"aggs": {
"propertyGrouping": {
"terms": {
"field": "propertyId",
"size": 10
}
, "aggs": {
"dupReviwes": {
"terms": {
"field": "reviewKeyword",
"size": 100
}
}
}
}
}
现在我还想要的是子聚合返回的文档计数总和。 这是样本回复
{
"buckets": [
{
"key": 532,
"doc_count": 2431,
"dupReviwes": {
"doc_count_error_upper_bound": 10,
"sum_other_doc_count": 2382,
"buckets": [
{
"key": "Good hotel",
"doc_count": 31
},
{
"key": "Overall good",
"doc_count": 18
}
]
}
},
{
"key": 496,
"doc_count": 2207,
"dupReviwes": {
"doc_count_error_upper_bound": 8,
"sum_other_doc_count": 2185,
"buckets": [
{
"key": "Good",
"doc_count": 16
},
{
"key": "Nice",
"doc_count": 6
}
]
}
}
]
}
所以我也想要每个存储桶的文档计数总和 因此对于上述情况:对于两个键
Key : 532
sum_doc_count=49 (31+18)
key : 496
sum_doc_count=32 (16 + 6)
某些查询可能吗?
答案 0 :(得分:1)
是的,您可以使用sum_bucket
pipeline aggregation轻松地实现这一点,只需像这样修改查询即可:
{
"query": {
"bool": {
"must_not": [
{
"term": {
"reviewKeyword": {
"value": ""
}
}
}
]
}
},
"aggs": {
"propertyGrouping": {
"terms": {
"field": "propertyId",
"size": 10
},
"aggs": {
"dupReviews": {
"terms": {
"field": "reviewKeyword",
"size": 100
}
},
"sum_buckets": {
"sum_bucket": {
"buckets_path": "dupReviews>_count"
}
}
}
}
}
}