2014-06-08 105 views
3

我试着去创建一个查询,就会发现,无论是包含所有#breakingbad状态或“破坏”Elasticsearch |匹配多个短语

这里是我到目前为止,但其根据感明显错误:

{ 
    "query": { 

     "match": { 

     "_all": { 

      "query": "breaking bad", 
      "type": "phrase" 
     } 
     }, 
     "match": { 
     "_all": { 
      "query": "#breakingbad", 
      "type": "phrase" 
     } 
    } 
} 
+0

你有没有尝试在bool查询中嵌入你的匹配查询? – l4rd

回答

3

答:

{ 
    "query": { 
     "bool": { 
      "should": [ 
       { 
        "match": { 
         "message": { 
          "query": "breaking bad", 
          "type": "phrase" 
         } 
        } 
       }, 
       { 
        "match": { 
         "message": "#poznasty" 
        } 
       } 
      ] 
     } 
    } 
} 
1

为什么不使用multi_match

{ 
    "query" : { 
     "multi_match" : { 
      "fields" : ["name", "description"], 
      "query" : "breaking bad", 
      "type" : "phrase_prefix" 
     } 
    } 
} 

MultiMatchQueryBuilder builder = QueryBuilders.multiMatchQuery(query, 
    "name", "description").type(MatchQueryBuilder.Type.PHRASE_PREFIX);