【发布时间】:2016-04-21 09:59:13
【问题描述】:
我在返回一个关于拼写错误的 Ngram 的好建议时遇到了问题。 让我详细解释一下。
考虑以下在“标题”字段上使用 shingle 过滤器的映射:
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"
}
}
}
}
}
}
}
将一个包含“carla bruni”的文档添加到索引 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
}
}
}
}
返回如下结果,正是我需要的:
{
"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"
}
然后使用建议再次搜索:没有给出建议,因为在索引中找到了 'bruno',并且 elasticsearch 认为它是有效的。
你知道我怎样才能让建议返回“carla bruni”作为建议吗?
【问题讨论】:
标签: elasticsearch search-suggestion