【发布时间】:2019-08-30 19:57:37
【问题描述】:
我们有分面显示点击过滤器(并组合它们)时将显示的结果数量。像这样的:
在我们引入嵌套对象之前,以下内容可以完成这项工作:
GET /x_v1/_search/
{
"size": 0,
"aggs": {
"FilteredDescriptiveFeatures": {
"filter": {
"bool": {
"must": [
{
"terms": {
"breadcrumbs.categoryIds": [
"category"
]
}
},
{
"terms": {
"products.sterile": [
"0"
]
}
}
]
}
},
"aggs": {
"DescriptiveFeatures": {
"terms": {
"field": "products.descriptiveFeatures",
"size": 1000
}
}
}
}
}
}
这给出了结果:
"aggregations": {
"FilteredDescriptiveFeatures": {
"doc_count": 280,
"DescriptiveFeatures": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "somekey",
"doc_count": 42
},
虽然我们需要将products 设为嵌套对象,但我目前正在尝试重写上述内容以处理此更改。
我的尝试如下所示。但它没有给出正确的结果,并且似乎没有正确连接到过滤器。
GET /x_v2/_search/
{
"size": 0,
"aggs": {
"FilteredDescriptiveFeatures": {
"filter": {
"bool": {
"must": [
{
"terms": {
"breadcrumbs.categoryIds": [
"category"
]
}
},
{
"nested": {
"path": "products",
"query": {
"terms": {
"products.sterile": [
"0"
]
}
}
}
}
]
}
},
"aggs": {
"nested": {
"nested": {
"path": "products"
},
"aggregations": {
"DescriptiveFeatures": {
"terms": {
"field": "products.descriptiveFeatures",
"size": 1000
}
}
}
}
}
}
}
}
这给出了结果:
"aggregations": {
"FilteredDescriptiveFeatures": {
"doc_count": 280,
"nested": {
"doc_count": 1437,
"DescriptiveFeatures": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "somekey",
"doc_count": 164
},
我还尝试将嵌套定义放在更高的位置以同时包含过滤器和 aggs,但是不在嵌套对象中的过滤器术语 breadcrumbs.categoryId 将不起作用。
我正在尝试做的事情是否可能? 又该如何解决?
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation