我是Elasticsearch的新手,正在尝试将两件事结合起来...
我正在使用n-gram来部分搜索我的索引,这在这里工作正常:
"mappings": {
"post": {
"properties": {
"title": {
"type": "text",
"analyzer": "autocomplete"
}
}
}
},
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
因此,部分搜索效果很好,但我也想在此搜索中添加同义词。
所以说我有两个文件。一种包含“勒布朗”,另一种包含“神户”。现在,如果我查询“ lebr” ...“ lebron”出现了,我想保持这种行为。但是,我想添加“神户”作为“勒布朗”的同义词。因此,如果我查询完整的单词“ lebron”,则将同时返回“ kobe”和“ lebron”。这种行为可能吗?
我尝试将其设置为多字段并添加另一个分析器,但是我不确定这是否在正确的轨道上...
"mappings": {
"post": {
"properties": {
"title": {
"type": "text",
"analyzer": "autocomplete",
"fields": {
"raw": {
"type": "text",
"analyzer": "synonym"
}
}
}
}
}
},
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
},
"synonym" : {
"type" : "synonym",
"synonyms" : [
"LeBron, Kobe",
"Lebron => Kobe"
]
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
},
"synonym": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym"
]
}
}
}
}
感谢您的帮助。