2016-03-24 52 views
1

我試圖在交叉字段查詢中的特定字段上實現模糊性。雖然這有點困難。如何在elasticsearch中添加模糊搜索查詢?

所以查詢應該:

  1. 跨領域匹配的短語。
  2. 匹配partNumber和條碼的精確匹配(無模糊)
  3. 匹配模糊條款與標題和副標題。

我到目前爲止的查詢如下 - 請注意模糊在查詢中目前爲止根本不起作用。

所以這應該匹配1個結果,即標題中的「驚人的T恤」和副標題中的藍色。 (注意拼寫錯誤)。

是否可以在索引映射級別實現模糊性?數據集中的標題和副標題非常短 - 最多可組合30-40個字符。

否則,如何將模糊添加到查詢中的標題和副標題?

{ 
    "query": { 
    "multi_match": { 
     "query": "Bleu Amazing T-Shirt", 
     "fuzziness": "auto", 
     "operator": "and", 
     "fields": [ 
      "identity.partNumber^4", 
      "identity.altIdentifier^4", 
      "identity.barcode", 
      "identity.mpn", 
      "identity.ppn", 
      "descriptions.title", 
      "descriptions.subtitle" 
     ], 
     "type": "cross_fields" 
     } 
    }, 
    "fields": [ 
    "identity.partNumber", 
    "identity.barcode", 
    "identity.ppn", 
    "descriptions.title", 
    "descriptions.subtitle" 
    ] 
} 

回答

0

好吧,它似乎不支持模糊搜索使用cross_fields,有幾個相關的問題。因此,我不是跨域搜索,而是在索引時將標題&複製到新字段,並像下面那樣拆分查詢。似乎至少爲我的測試案例工作....

"query": { 
     "bool": { 
     "should": [ 
      { 
      "multi_match": { 
       "query": "{{searchTerm}}", 
       "operator": "and", 
       "fields": [ 
       "identity.partNumber^4", 
       "identity.altIdentifier^4", 
       "identity.barcode", 
       "identity.mpn", 
       "identity.ppn" 
       ], 
       "type": "best_fields" 
      } 
      }, 
      { 
      "match": { 
       "fuzzyFields": { 
       "query": "{{searchTerm}}", 
       "operator": "and", 
       "fuzziness": "auto" 
       } 
      } 
      } 
     ] 
     } 
    }