简体   繁体   English

match_phrase elasticsearch中的可选术语

[英]Optional terms in match_phrase elasticsearch

I am using elasticsearch 6 and have the following query 我正在使用elasticsearch 6并有以下查询

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

     ]
  }
 }
}

This works well when I want to match on the two fields with the terms in the query. 当我想在两个字段上与查询中的术语进行匹配时,此方法效果很好。

However if I have a document which has term 'one' and 'two' in fieldOne the above does not return results as 'three' is required 但是,如果我在fieldOne中有一个术语为“一”和“二”的文档,则上面的结果不会返回结果,因为需要“三”

I cannot seems to find a way of making the terms in the query optional eg what I wanted is to say find any of the terms in those two fields 我似乎找不到一种使查询中的术语可选的方式,例如,我要说的是在这两个字段中找到任何术语

The reason I went with match_phrase is the use of the slop which allows the terms to be in different positions in the field which i also require 我使用match_phrase的原因是使用slop,它允许术语在字段中的不同位置,我也需要

if the order is not important to use, you don't need to use match_phrase , a simple match query does the job 如果使用顺序不重要,则无需使用match_phrase ,简单的match查询即可完成工作

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

Then if you need at least two terms to match you can do so using minimum_should_match : 然后,如果您需要至少两个词来匹配,则可以使用minimum_should_match

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM