2014-06-08 130 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);