2016-09-15 73 views
0

我有一個小問題,我開始使用Elasticsearch並且在使用我的curl腳本測試時遇到此問題。Elasticsearch multi_match在單詞開頭

curl -XGET 'localhost:9200/fcomputer/products/_search?pretty' -d' 
{ 
    "query" : { 
     "multi_match" : { 
      "query" : "sams evo", 
"fields": ["title", "fulltext"] 
     } 
    } 
}' 

我在所有包含或開始sams和evo後嘗試搜索,我不關心區分大小寫。

現在它看起來好像是關閉了正確的話,當我輸入和它的使用一種「或」在sams和evo上。

是否有一個簡單的方法來告訴查詢:

  1. 搜索現場:標題和全文

  2. 如果您發現場比賽這兩個詞(SAMS & EVO)匹配的財產以後(開始)或(100%匹配)

  3. 返回所有有效數據返回搜索。

我一直在試圖找到這個標題的比賽:

  • 三星950 PRO MZ-V5P256BW - 固態硬盤 - 256 GB - 的PCI Express 3.0×4(NVMe

  • ASUS GTX950-2G grafikkort - GF GTX 950 - 2 G

  • ASUS GTX950-OC-2GD5 grafikkort - GF GTX 950 - 2 GB

  • Zebra Z-Ultimate 5A - permanentklæbende空白polyestertape - 950 stk。

  • 京瓷TK 950 - 排序 - 原創 - tonerpatron

這裏唯一的匹配關是(三星950 PRO),如果我用搜索詞 「三星950」,但它不工作。

回答

1

試試這個

{ 
    "query": { 
    "multi_match": { 
     "query": "sam evo", 
     "type": "cross_fields", 
     "operator": "and", 
     "fields": [ 
     "title", 
     "fulltext" 
     ] 
    } 
    } 
} 

使用此設置

{ 
    "settings": { 
     "analysis": { 
      "filter": { 
       "autocomplete_filter": { 
        "type":  "edge_ngram", 
        "min_gram": 1, 
        "max_gram": 20 
       } 
      }, 
      "analyzer": { 
       "autocomplete": { 
        "type":  "custom", 
        "tokenizer": "standard", 
        "filter": [ 
         "lowercase", 
         "autocomplete_filter" 
        ] 
       } 
      } 
     } 
    } 
} 

和映射

{ 
    "properties": { 
    "title": { 
     "type": "string", 
     "analyzer": "autocomplete", 
     "search_analyzer": "standard" 
    }, 
    "fulltext": { 
     "type": "string", 
     "analyzer": "autocomplete", 
     "search_analyzer": "standard" 
    } 
    } 
} 
+0

其仍然沒有像這個詞的begning搜索 「三星750 EVO」 不會在此查詢中找到。 – ParisNakitaKejser

+0

立即嘗試設置和映射。 – blackmamba

+0

你可以爲它創建一個捲曲嗎?可以看到你的意思,但不明白如何使用它,我現在非常新的Elasticsearch :) – ParisNakitaKejser

相關問題