match_phrase elasticsearch 中的可选术语

Optional terms in match_phrase elasticsearch

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

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

     ]
  }
 }
}

当我想将两个字段与查询中的字词进行匹配时,这很有效。

但是,如果我的文档在 fieldOne 中包含术语 'one' 和 'two',则上述内容不会 return 结果,因为 'three' 是必需的

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

我选择 match_phrase 的原因是使用斜率,它允许术语在字段中处于不同位置,我也需要

如果使用顺序不重要,则不需要使用 match_phrase,一个简单的 match 查询就可以了

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

然后,如果您需要至少两个字词来匹配,您可以使用 minimum_should_match:

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