2014-07-03 72 views
9

因此ElasticSearch具有条款查询,该查询允许我提供多个值并返回字段X与这些值中的任何值匹配的文档集。如何在ElasticSearch中执行多个“匹配”或“match_phrase”值

但我想用match_phrase做同样的事情 - 即返回文档,其中字段X包含空格的术语不区分大小写的匹配。我目前正在使用一个或一个过滤器(见下文)。但是,这看起来像是一种非常冗长的做我想做的事情的方式,考虑到术语已经做了类似的事情。

当前方法

看来荒谬的查询搜索一个字段的三个值应该是33线长。

{ 
    "query": { 
    "filtered": { 
     "filter": { 
      "or": { 
       "filters": [ 
       { 
        "query": { 
         "match_phrase": { 
          "myField1": "My first search phrase" 
         } 
        } 
       }, 
       { 
        "query": { 
         "match_phrase": { 
          "myField1": "My second search phrase" 
         } 
        } 
       }, 
       { 
        "query": { 
         "match_phrase": { 
          "myField1": "My third search phrase" 
         } 
        } 
       } 
       ] 
      } 
     } 
    } 
    } 
} 

回答

3

Query string会有帮助这里在这些线路上的东西

{ 
     "query": { 
     "query_string": { 
      "default_field": "myField1", 
      "query": "\"My first search phrase\" OR \"My second search phrase\" OR \"My third search phrase\"" 
     } 
     } 
    }