gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 5 中向 function_score 查询添加过滤器

转载 作者:行者123 更新时间:2023-11-29 02:51:54 26 4
gpt4 key购买 nike

如何在 Elasticsearch 5.2.0 中将此过滤器添加到下面的查询中。

我试图将过滤器包装在过滤数组中,但没有成功。

过滤器

"filter" : {
"term" : { "body.category" : 1}
}

查询

{
"query": {
"function_score": {
"query": {
"multi_match": {
"operator": "and",
"query": "my search",
"fuzziness": 1,
"fields": [
"body.name^5",
"body.manufacturer^33",
"body.sections.name",
"body.sections.parent.name",
"body.sections.parent.parent.name"
]
}
},
"functions": [
{
"field_value_factor": {
"field": "body.rank"
}
}
],
"score_mode": "multiply"
}
}
}

最佳答案

我通过用 bool 值包装查询并将过滤器放在那里解决了这个问题。

   {
"query": {
"function_score": {
"query": {
"bool": {
"filter": {
"term": {
"body.category": 1
}
},
"should": {
"multi_match": {
"operator": "and",
"query": "my search",
"fuzziness": 1,
"fields": [
"body.name",
"body.manufacturer",
"body.sections.name",
"body.sections.parent.name",
"body.sections.parent.parent.name"
]
}
}
}
},
"functions": [
{
"field_value_factor": {
"field": "body.rank"
}
}
],
"score_mode": "multiply"
}
}
}

关于elasticsearch - 如何在 Elasticsearch 5 中向 function_score 查询添加过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42279851/

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