gpt4 book ai didi

elasticsearch - 如何从构面中排除过滤器?

转载 作者:行者123 更新时间:2023-12-02 22:16:20 25 4
gpt4 key购买 nike

我有 Solr 背景,正在尝试找到 "tagging" and "excluding" 的等价物在 Elasticsearch 中。

在下面的示例中,如何从 prices facet 的计算中排除 price 过滤器?换句话说,prices 方面应该考虑除 price 之外的所有过滤器。

{
query : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"and" : [
{
"term" : {
"colour" : "Red"
}
},
{
"term" : {
"feature" : "Square"
}
},
{
"term" : {
"feature" : "Shiny"
}
},
{
"range" : {
"price" : {
"from" : "10",
"to" : "20"
}
}
}
]
}
}
},
"facets" : {
"colours" : {
"terms" : {
"field" : "colour"
}
},
"features" : {
"terms" : {
"field" : "feature"
}
},
"prices" : {
"statistical" : {
"field" : "price"
}
}
}
}

最佳答案

您可以将价格过滤器作为顶级过滤器应用于您的查询,并将其作为 facet_filter 添加到期望价格的所有方面:

{
query : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"and" : [
{
"term" : {
"colour" : "Red"
}
},
{
"term" : {
"feature" : "Square"
}
},
{
"term" : {
"feature" : "Shiny"
}
}
]
}
}
},
"facets" : {
"colours" : {
"terms" : {
"field" : "colour"
},
"facet_filter" : {
"range" : { "price" : { "from" : "10", "to" : "20" } }
}
},
"features" : {
"terms" : {
"field" : "feature"
},
"facet_filter" : {
"range" : { "price" : { "from" : "10", "to" : "20" } }
}
},
"prices" : {
"statistical" : {
"field" : "price"
}
}
},
"filter": {
"range" : { "price" : { "from" : "10", "to" : "20" } }
}
}

关于elasticsearch - 如何从构面中排除过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15649179/

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