2016-02-07 47 views
0

我想提高查詢,如果它的匹配措辭,但我希望它只能在某個領域進行搜索。 。到目前爲止,我有以下查詢如何增強短語匹配,但只是在某些領域?

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match_phrase": { 
      "_all": { 
       "query": "string", 
       "boost": 5 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

但因爲我不指定它應該在搜索領域返回幾個結果我嘗試這樣做另一種方法:

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match_phrase": { 
      "_all": { 
       "query": "string", 
       "fields": [ 
       "filed_name" 
       ], 
       "boost": 5 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

,但我得到了錯誤

[搭配]查詢不支持[場]

回答

1

您可以使用multi match查詢並使用phrase type在特定字段中執行match_phrase

{ 
    "query": { 
    "multi_match": { 
     "query": "some string", 
     "fields": ["title","summary"], 
     "type": "phrase" 
    } 
    } 
} 
+0

是的,謝謝@ ChintanShah25!這就是我最終做的。 您也可以通過這種方式包含一個模糊參數。 例如: { 「查詢」:{ 「multi_match」:{ 「查詢」: 「一些字符串」, 「字段」:[ 「標題」, 「摘要」], 「類型」:「短語「, 」模糊「:」AUTO「 } } } –

+0

很高興我可以幫忙 – ChintanShah25