2016-04-21 135 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 
      } 
     } 
     } 
    } 
}