在我将同义词文件添加到索引后,模糊性停止工作。看来,不可能同时使用它们。 我的询问:
"query": {
"dis_max": {
"queries": [{
"multi_match": {
"query": $('#searchterm').val(),
"fields": ["search_1"],
"fuzziness": "AUTO",
"operator": "and",
"max_expansions": 1
}},
{ "match": { "search_2": $('#searchterm').val() }}
]
}
}
映射:
"mappings": {
"objs":{
"properties": {
"o":{
"type": "string"
},
"loc":{
"type":"geo_point"
},
"search_1":{
"type": "string",
"analyzer": "synonym"
},
"search_2":{
"type": "string",
"analyzer": "synonym"
}
}
}
我刚刚遇到了同样的问题,似乎你不能混合它们,有人已经为此打开了一个 github 问题:https://github.com/elastic/elasticsearch/issues/25518 该问题已关闭并且他们更新了文档: https://github.com/elastic/elasticsearch/blob/master/docs/reference/query-dsl/match-query.asciidoc
这是有趣的部分:
请注意,模糊匹配不适用于具有同义词的术语,如 在幕后,这些术语被扩展为特殊的同义词查询 混合词频,不支持模糊扩展。
我遇到了同样的问题,我所做的解决方法是为所有同义词创建一个索引,然后使用模糊性搜索同义词索引,以获得它的正确拼写,然后假设您获得了 2 或 3 个命中,现在这些命中是原始索引上同义词的正确拼写,现在您可以在原始索引上使用模糊性来搜索它们。
这样,您仅在同义词上进行模糊搜索。