json - 如何过滤嵌套聚合

标签 json elasticsearch

我正在尝试对不同的嵌套聚合应用不同的过滤器。有没有办法做到这一点?

"filter": {
    "nested": {
        "path": "hierarchy.productGroup",
        "filter": {
            "terms": {
                "hierarchy.productGroup.name": ["iPhone"]
            }
        }
    }
},
"aggs": {
    "category": {
        "nested": {
            "path": "hierarchy.productGroup"
        },
        "aggs": {
            "category": {
                "terms": {
                    "field": "hierarchy.productGroup.name"
                }
            }
        }
    },
    "color": {
        "filter": {
            "nested": {
                "path": "hierarchy.productGroup",
                "filter": {
                    "terms": {
                        "hierarchy.productGroup.name": ["iPhone"]
                    }
                }
            }
        },
        "nested": {
            "path": "specs.measurementsProduct.colorName"
        },
        "aggs": {

            "color": {
                "terms": {
                    "field": "specs.measurementsProduct.colorName.name"
                }
            }
        }
    }
}

当我运行此查询时,出现以下错误:
Error: Parse Failure [Found two aggregation type definitions in [color]: [filter] and [nested]]];

我想使我的颜色聚合取决于类别过滤器。

最佳答案

您忘记了以开头的键和以结尾的键。
尝试使用此json:

{
    "filter": {
        "nested": {
            "path": "hierarchy.productGroup",
            "filter": {
                "terms": {
                    "hierarchy.productGroup.name": ["iPhone"]
                }
            }
        }
    },
    "aggs": {
        "category": {
            "nested": {
                "path": "hierarchy.productGroup"
            },
            "aggs": {
                "category": {
                    "terms": {
                        "field": "hierarchy.productGroup.name"
                    }
                }
            }
        },
        "color": {
            "filter": {
                "nested": {
                    "path": "hierarchy.productGroup",
                    "filter": {
                        "terms": {
                            "hierarchy.productGroup.name": ["iPhone"]
                        }
                    }
                }
            },
            "nested": {
                "path": "specs.measurementsProduct.colorName"
            },
            "aggs": {
                "color": {
                    "terms": {
                        "field": "specs.measurementsProduct.colorName.name"
                    }
                }
            }
        }
    }
}

关于json - 如何过滤嵌套聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28585676/

相关文章:

python - Django ORM 和 Django REST 框架 : How to make "grouped" arrays?

ruby-on-rails - 按状态过滤轮胎结果

search - 使用 elasticsearch 集群和 Web 服务器集群避免单点故障的最佳方法

elasticsearch - 如何在Elasticsearch中的列表中的所有元素上应用 bool 查询?

json - JSON 的 xpath 与 XML 不同

javascript - 如何通过javascript访问选中的单选框的值

elasticsearch - 由于 IDF 的不同 maxDocs 而导致评分不佳

c# - ElasticSearch NEST searchresponse.hits 数据未填充

java - 使用 Jackson 解析非同质 JSON 对象数组

php - 使用 PHP 对 JSON 进行分组