gpt4 book ai didi

elasticsearch - 用于 “field does not exist OR field is equal to true”的Elasticsearch过滤器

转载 作者:行者123 更新时间:2023-12-03 00:46:36 27 4
gpt4 key购买 nike

我有以下格式的搜索查询:

{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"simple_query_string": {
"query": "*",
"fields": [
"field1^10",
"field2^3"
]
}
},
"filter": [
{
"terms": {
"field3": [
"val1",
"val2"
]
}
},
{
"terms": {
"field4": [
"val4"
]
}
},
{
"term": {
"field5": true
}
}
]
}
},
"functions": [
{
"gauss": {
"field1": {
"scale": "31d"
}
},
"weight": 5
}
],
"score_mode": "sum",
"boost_mode": "multiply"
}
},
"size": 10
}

现在,我想修改 field5上的过滤器,以使其过滤将field5设置为 true或未将 field5索引的值。我想要两种结果,并且只想排除那些 field5设置为false的结果。

我已经尝试在 must_not中将 shouldfilter进行各种组合,但是还无法使查询正常工作。谢谢您的帮助!

我正在使用Elasticsearch 6.5.1版。

最佳答案

鉴于您特别提供的信息

I want both kinds in the results and want to exclude only the ones which have field5 set to false.



查询应如下所示:
{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"simple_query_string": {
"query": "*",
"fields": [
"field1^10",
"field2^3"
]
}
},
"must_not": [
{
"term": {
"field5": {
"value": false
}
}
}
],
"filter": [
{
"terms": {
"field3": [
"val1",
"val2"
]
}
},
{
"terms": {
"field4": [
"val4"
]
}
}
]
}
},
"functions": [
{
"gauss": {
"field1": {
"scale": "31d"
}
},
"weight": 5
}
],
"score_mode": "sum",
"boost_mode": "multiply"
}
},
"size": 10
}

我添加了must_not-clause来排除所有具有field5等于false的文档。

关于elasticsearch - 用于 “field does not exist OR field is equal to true”的Elasticsearch过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59899735/

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