2016-04-21 86 views
0

我有一個問題,返回拼寫錯誤的Ngrams的好建議。 讓我詳細解釋。短語推薦elasticsearch

考慮在「標題」字段與屋頂板過濾器下面的映射:

PUT _template/test_news_flo 
{ 
"template": "test_articles_flo", 
"settings": { 
    "number_of_shards": 1, 
    "number_of_replicas": 2, 
    "analysis": { 
     "filter": { 
      "filter_shingle":{ 
       "type":"shingle", 
       "max_shingle_size":5, 
       "min_shingle_size":2, 
       "output_unigrams":"true" 
      } 

     }, 
     "analyzer": { 
      "analyzer_shingle":{ 
       "tokenizer":"standard", 
       "filter":["standard", "lowercase", "filter_shingle"] 
      } 
     } 
    } 
}, 
"mappings": { 
    "article": { 
     "_all": { "enabled": false }, 
     "properties": { 
      "title": { 
       "norms": { 
        "enabled": false 
       }, 
       "type": "string", 
       "fields": { 
        "shingle": { 
         "search_analyzer":"analyzer_shingle", 
         "index_analyzer":"analyzer_shingle", 
         "type":"string" 
         } 
        } 
       } 
      } 
     } 
    } 
} 

添加含有「卡拉布魯尼」到索引test_articles_flo

POST /test_articles_flo/article 
{ 
    "title": "Carla Bruni scintillante pour le Sidaction" 
} 

然後運行以下一個文檔建議短語查詢:

POST /test_articles_flo/_search/?size=0 
{ 
"suggest": { 
    "suggest-phrase-title": { 
    "text": "Carla bruno", 
    "phrase": {  
     "field": "title.shingle", 
     "confidence": 1, 
     "size": 5, 
     "gram_size": 2, 
     "max_errors": 2 
     } 
    } 
    } 
} 

返回以下結果whi CH正是我需要的:

 { 
     "text": "Carla bruno", 
     "offset": 0, 
     "length": 11, 
     "options": [ 
      { 
       "text": "carla bruni", 
       "score": 0.24166171 
      } 
     ] 
    } 

現在添加另一篇文章:

POST /test_articles_flo/article 
{ 
    "title": "Le réveil de Massimo Bruno" 
} 

然後再次搜索提示:不建議給出「布魯諾」在索引中被發現,elasticsearch認爲作爲有效。

你知道我怎麼能建議回報'卡拉bruni'作爲一個建議?

回答

0

似乎增加了direct_generator時按預期方式工作:

這裏是查詢

POST /test_articles_flo/_search/?size=0 
{ 
    "suggest": { 
     "suggest-phrase-title": { 
     "text": "jonnhy dep", 
     "phrase": {  
      "field": "title.shingle", 
      "confidence": 1, 
      "size": 5, 
      "gram_size": 2, 
      "max_errors": 5, 
      "direct_generator" : [ { 
       "field" : "title.shingle", 
       "suggest_mode" : "always", 
       "min_word_length" : 1 
      }], 
      "collate": { 
       "query": { 
        "match_phrase": { 
        "{{field_name}}": "{{suggestion}}" 
        } 
       }, 
       "params": { 
        "field_name": "title.shingle" 
       }, 
       "prune": false 
      } 
     } 
     } 
    } 
}