2017-03-25 66 views
0

在Elasticsearch我想找到與我的搜索字段相關的相關記錄,如與stackoverflow相關的問題建議。這意味着,匹配搜索結果是靠近一個另一個。如何找到與我的搜索字段在Elasticsearch相關的記錄

比如我搜索「男士鞋」,從以下數據

  1. 「男士鞋」
  2. 「女孩的鞋」
  3. 「男士鞋黑色」
  4. 「女鞋」
  5. 「女鞋粉紅色」
  6. 「女鞋紅色」
  7. 「男童鞋」
  8. 「男士鞋灰色」
  9. 「男士鞋的白色」
  10. 「男士鞋綠色」
  11. 「男士鞋」

然後,我怎麼可以得到更多相關的元組項目「男鞋」?我怎樣才能得到與同義詞相關的數據也就是說。男人的鞋子。

在Kibana
POST /atomap/product/_bulk 
{"index":{"_id":"1"}} 
{"name": "Girl's Shoe"} 
{"index":{"_id":"2"}} 
{"name": "Men's Shoe"} 
{"index":{"_id":"3"}} 
{"name": "Women's Shoe"} 
{"index":{"_id":"4"}}  
{"name": "Women's Shoe pink color"} 
{"index":{"_id":"5"}} 
{"name": "Women's Shoe red color"} 
{"index":{"_id":"6"}} 
{"name": "Boy's Shoe"} 
{"index":{"_id":"7"}} 
{"name": "Men's Shoe red color"} 
{"index":{"_id":"8"}} 
{"name": "Men's Shoe white color"} 
{"index":{"_id":"9"}} 
{"name": "Men's Shoe green color"} 
{"index":{"_id":"10"}} 
{"name": "Men's Shoe gray color"} 
{"index":{"_id":"11"}} 
{"name": "Men's footwear"} 

散裝Inser我試圖與more like this查詢:

GET /atomap/product/_search 
{ 
    "query": { 
    "more_like_this": { 
     "like": "Men's shoe", 
     "min_term_freq": 1, 
     "min_doc_freq": 1 
    } 
    } 
} 

我的問題是怎樣搜尋相關的字?由於More Like This Query在搜索「男士鞋」時找不到「男士鞋類」。

回答

1

創建同義詞和字段映射:

PUT /atomap 
{ 
    "settings": { 
    "analysis": { 
     "filter": { 
     "my_synonym_filter": { 
      "type": "synonym", 
      "synonyms": [ 
      "shoe,footwear", 
      "color,colour" 
      ] 
     } 
     }, 
     "analyzer": { 
     "my_synonyms": { 
      "tokenizer": "standard", 
      "filter": [ 
      "lowercase", 
      "my_synonym_filter" 
      ] 
     } 
     } 
    } 
    }, 
    "mappings":{ 

    "product" : { 
    "properties" : { 
     "name" : { 
      "type" : "string", 
      "analyzer" : "my_synonyms" 
     } 
    } 
    } 

    } 
} 

然後插入的所有數據,之後運行以下查詢:

POST /myshop/_search 
{ 
    "query": { 
     "query_string": { 
      "default_field": "name", 
      "query": "Men's shoe", 
      "analyzer": "my_synonyms" 
     } 
    } 
} 
0

當我運行查詢(對索引atomap代替my_test

GET /atomap/product/_search 
{ 
    "query": { 
    "more_like_this": { 
     "like": "Men's shoe", 
     "min_term_freq": 1, 
     "min_doc_freq": 1 
    } 
    } 
} 

我得到Men's footwear與得分0.62191015第四結果。在Elasticsearch 5.2上測試。

PS:提供測試數據和查詢的獎勵積分。否則就沒有機會重現這一點。

+0

這是我的索引名稱的錯誤。但我想在第三個位置有'男士鞋',即。 「女鞋」之前 –

相關問題