gpt4 book ai didi

elasticsearch - ElasticSearch 2.1.0-带有 'children'指标的深度 'sum'聚合返回空结果

转载 作者:行者123 更新时间:2023-12-02 23:33:14 26 4
gpt4 key购买 nike

我有两个层次的文档类型层次结构。这些文档由parent-child relationships关联如下:category> sub_category> item,即每个sub_category都有一个引用类别ID的_parent字段,而每个项目都有一个subt_category id的_parent字段。

每个项目都有一个price字段。给定一个类别查询,其中包括子类别和项目的条件,我想计算每个sub_category的总价。

我的查询看起来像这样:

{
"query": {
"has_child": {
"child_type": "sub_category",
"query": {
"has_child": {
"child_type": "item",
"query": {
"range": {
"price": {
"gte": 100,
"lte": 150
}
}
}
}
}
}
}
}

我计算每个子类别价格的汇总如下所示:
{
"aggs": {
"categories": {
"terms": {
"field": "id"
},
"aggs": {
"sub_categories": {
"children": {
"type": "sub_category"
},
"aggs": {
"sub_category_ids": {
"terms": {
"field": "id"
},
"aggs": {
"items": {
"children": {
"type": "item"
},
"aggs": {
"price": {
"sum": {
"field": "price"
}
}
}
}
}
}
}
}
}
}
}
}

尽管查询响应列出了匹配结果,但聚合响应不匹配任何项目:
{
"aggregations": {
"categories": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "category1",
"doc_count": 1,
"sub_categories": {
"doc_count": 3,
"sub_category_ids": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "subcat1",
"doc_count": 1,
"items": {
"doc_count": 0,
"price": {
"value": 0
}
}
},
{
"key": "subcat2",
"doc_count": 1,
"items": {
"doc_count": 0,
"price": {
"value": 0
}
}
},
{
"key": "subcat3",
"doc_count": 1,
"items": {
"doc_count": 0,
"price": {
"value": 0
}
}
}
]
}
}
}]
}
}
}

但是,省略 sub_category_ids聚合确实会导致项目出现,并且价格会在 categories聚合的级别进行汇总。我希望包括 sub_category_ids聚合来简单地改变价格总和的水平。

我是否误解了汇总的评估方式,如果是这样,如何修改它以显示每个子类别的汇总价格?

最佳答案

我打开了一个#15413问题,关于children aggregation,因为我和其他人在ES 2.0中都面临着类似的问题

显然,根据ES开发人员@martijnvg的问题是

The children agg makes an assumption (that all segments are being seen by children agg) that was true in 1.x but not in 2.x



PR #15457再次通过@martijnvg解决了此问题

Before we only evaluated segments that yielded matches in parent aggs, which caused us to miss to evaluate child docs in segments we didn't have parent matches for.

The fix for this is stop remember in what segments we have matches for and simply evaluate all segments. This makes the code simpler and we can still quickly see if a segment doesn't hold child docs like we did before



此合并请求已被合并,并且也已将 反向移植移植到 2.x, 2.1 and 2.0 branches

关于elasticsearch - ElasticSearch 2.1.0-带有 'children'指标的深度 'sum'聚合返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34222753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com