gpt4 book ai didi

elasticsearch - match_phrase elasticsearch中的可选术语

转载 作者:行者123 更新时间:2023-12-03 01:36:37 30 4
gpt4 key购买 nike

我正在使用elasticsearch 6并有以下查询

{  
"query":{
"bool":{
"should":[
{
"match_phrase":{
"fieldOne":{
"query":"One two three",
"slop":10
}
}
},
{
"match_phrase":{
"fieldTwo":{
"query":"one two three",
"slop":10
}
}
}

]
}
}
}

当我想将两个字段与查询中的术语进行匹配时,此方法效果很好。

但是,如果我在fieldOne中有一个术语为“一”和“二”的文档,则上面的结果不会返回结果,因为需要“三”

我似乎找不到一种使查询中的术语成为可选的方式,例如我要说的是找到这两个字段中的任何一个

我使用match_phrase的原因是使用slop,它允许术语在字段中的不同位置,我也需要

最佳答案

如果使用顺序不重要,则无需使用match_phrase,简单的match查询即可完成工作

    {  
"match":{
"fieldOne":{
"query":"one two three"
}
}
},

然后,如果您需要至少两个词来匹配,则可以使用 minimum_should_match 进行匹配:
    {  
"match":{
"fieldOne":{
"query":"one two three",
"minimum_should_match": 2
}
}
},

关于elasticsearch - match_phrase elasticsearch中的可选术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51968002/

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