我试着让弹性搜索在城市列表中进行语音搜索。我的目标是找到匹配的结果,即使用户使用不正确的拼写。
我已经完成了以下步骤:
curl "localhost:9200/city/"删除-X
curl -X将“localhost:9200/city/?-H”内容-Type: application/json‘-d’{“-d”{“设置”:{“索引”:{“分析”:{“分析”:{ "my_analyzer":{“令牌器”:“标准”,“筛选”:“小写”、"my_metaphone“}、”筛选“:{ "my_metaphone":{”类型“:”语音“、”编码器“:"metaphone",“替换”:“:true }”,“映射”:{ "properties":{ "name":{ "type":"text",“分析器”:"my_analyzer“}'‘
curl -X将“localhost:9200/ -H /_doc/1?漂亮的”-H‘内容-类型: application/json’-d‘{ "name":"Mayrhofen“}}’curl -X PUT‘localhost:9200/city/_doc/2?漂亮的”-H’内容-类型: application/json‘-d’{-d“{名称:”Ischgl“}}‘-d’-X放置”localhost:9200/city/_doc/3?漂亮“--H 'Content-Type: application/json‘-d’{ "name":"Saalbach“} '‘
curl -X获取“”localhost:9200/ -H /_search?漂亮的“-H”内容-类型: application/json‘-d’{“查询”:{ "query_string":{“查询”:“Mayrhofen”}} '‘}’
我使用Mayerhofen尝试了这个查询,并期望得到与使用Mayrhofen相同的结果。Ischgl和Ichgl或Saalbach和Salbach也有同样的问题。
我的错误在哪里?有什么问题吗?
发布于 2020-07-14 09:08:17
问题是您使用了错误的encoder。metaphone无法与之相匹配。
您需要对输入使用double_metaphone。它基于语音算法的实现。我建议您了解您的数据和算法,以确保语音算法是否最适合您的目的。
制图:
{
"analysis": {
"analyzer": {
"double_meta_true_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"true_doublemetaphone"
]
}
},
"filter": {
"true_doublemetaphone": {
"type": "phonetic",
"encoder": "double_metaphone",
"replace": true
}
}
}
}它符合医生的要求。
为什么metaphone不匹配:
GET http://localhost:9200/city2/_analyze
{
"field":"meta_true",
"text":"Mayrhofen"
}收益率
{
"tokens": [
{
"token": "MRHF",
"start_offset": 0,
"end_offset": 9,
"type": "<ALPHANUM>",
"position": 0
}
]
}并分析如下
{
"field":"meta_true",
"text":"Mayerhofen"
}收益率
{
"tokens": [
{
"token": "MYRH",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
]
}Double_Metaphone的工作方式如下:
GET
{
"field":"doublemeta_true",
"text":"Mayerhofen"
}和
{
"field":"doublemeta_true",
"text":"Mayerhofen"
}和
{
"field":"doublemeta_true",
"text":"Mayrhofen"
}收益率
{
"tokens": [
{
"token": "MRFN",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
]
}https://stackoverflow.com/questions/62883549
复制相似问题