amazon-web-services - Elasticsearch 与语音搜索

标签 amazon-web-services elasticsearch elasticsearch-phonetic

我试图让Elastic Search在城市列表中进行语音搜索。我的目标是即使用户使用了不正确的拼写,也要找到匹配的结果。
我已完成以下步骤:

  • 删除域
    curl -X DELETE "localhost:9200/city/"
    
  • 创建新域
    curl -X PUT "localhost:9200/city/?pretty" -H 'Content-Type: application/json' -d'                                                      
    {
      "settings": {
        "index": {
          "analysis": {
            "analyzer": {
              "my_analyzer": {
                "tokenizer": "standard",
                "filter": [
                  "lowercase",
                  "my_metaphone"
                ]
              }
            },
            "filter": {
              "my_metaphone": {
                "type": "phonetic",
                "encoder": "metaphone",
                "replace": true
              }
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "name": {
            "type": "text",
            "analyzer": "my_analyzer"
          }
        }
      }
    }'
    
  • 填写一些样本数据
    curl -X PUT "localhost:9200/city/_doc/1?pretty" -H 'Content-Type: application/json' -d'
    {
       "name":"Mayrhofen"
    }
    '
    
    curl -X PUT "localhost:9200/city/_doc/2?pretty" -H 'Content-Type: application/json' -d'
    {
       "name":"Ischgl"
    }
    '
    
    curl -X PUT "localhost:9200/city/_doc/3?pretty" -H 'Content-Type: application/json' -d'
    {
       "name":"Saalbach"
    }
    '
    
  • 在城市中搜索-在这里我得到一个结果
    curl -X GET ""localhost:9200/city/_search?pretty" -H 'Content-Type: application/json' -d'
    {
       "query":{
          "query_string":{
             "query":"Mayrhofen" 
          }
       }
    }
    '
    

  • 我尝试使用 Mayerhofen 进行查询,并期望得到与使用 Mayrhofen 相同的结果。与 Ischgl Ichgl Saalbach Salbach 相同的问题。
    我的错误在哪里?有事吗?

    最佳答案

    问题是您使用了错误的encodermetaphone与之不符。
    您需要使用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
            }
        ]
    }
    

    关于amazon-web-services - Elasticsearch 与语音搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62883549/

    相关文章:

    java - 在hasParentQuery内部的Elasticsearch命名查询不起作用吗?

    python - Elasticsearch 通过搜索返回拼音标记

    elasticsearch - 为什么语音搜索比普通匹配查询慢得多

    elasticsearch - Elasticsearch:改善多重比赛结果

    elasticsearch - 对 elasticsearch 映射的更改是否适用于已索引的文档?

    amazon-web-services - 如何使用 importValue 并加入 Cloudformation

    c# - Serilog 与 .NET Core AWS 无服务器 Web API 项目

    amazon-web-services - 5分钟后移除模板

    android - 如何同时在 amazon web service s3 (Android) 中上传多张图片?