elasticsearch - Elasticsearch edgeNGram分析器/ token 器模糊查询匹配

标签 elasticsearch analyzer fuzzy

我们有一个Accounts表,正在使用edgeNGram分析器对多个字段进行模糊查询来搜索相似的记录。我们的设置:

设置

{
  settings: {
    analysis: {
      analyzer: {
        edge_n_gram_analyzer: {
          tokenizer: "whitespace",
          filter: ["lowercase",  "ednge_gram_filter"]
        }
      },
      filter: {
        ednge_gram_filter: {
          type: "edgeNGram",
          min_gram: 2,
          max_gram: 10
        }
      }
    }
  }
}

映射
{
  mappings: {
    document_type: {
      properties: {
        uid: {
          type: "text",
          analyzer: "edge_n_gram_analyzer"
        },
        shop_name: {
          type: "text",
          analyzer: "edge_n_gram_analyzer"
        },
        seller_name: {
          type: "text",
          analyzer: "edge_n_gram_analyzer"
        },
        ...
        ...
        ...
        locale_id: {
          type: "integer"
        }
      }
    }
  }
}

查询
{
  body: {
    query: {
      bool: {
        must: [
          {
            bool: {
              should: [
                {
                  fuzzy: {
                    uid: {
                      value: "antonline",
                      boost: 1.0,
                      fuzziness: 2,
                      prefix_length: 0,
                      max_expansions: 100
                    }
                  }
                },
                {
                  fuzzy: {
                    seller_name: {
                      value: "antonline",
                      boost: 1.0,
                      fuzziness: 2,
                      prefix_length: 0,
                      max_expansions: 100
                    }
                  }
                },
                {
                  fuzzy: {
                    shop_name: {
                      value: "antonline",
                      boost: 1.0,
                      fuzziness: 2,
                      prefix_length: 0,
                      max_expansions: 100
                    }
                  }
                }
              ]
            }
          }
        ],
        must_not: [
          {
            term: {
              locale_id: {
                value: 7
              }
            }
          }
        ]
      }
    }
  }
}

上面的示例查找“antonline”字符串的不同变体,例如“antonline”,“sanjonline”,“tanonline”,“kotonline”,“htonline”,“awmonline”。但是,它不匹配带有标点符号的字符串,例如antonline.com甚至不带点的antonlinecom。我们尝试了不同类型的 token 生成器,但无济于事。

我们如何才能达到预期的搜索结果?

最佳答案

我通过删除所有与此正则表达式匹配的东西解决了该问题:

[.,'\"\-+:~\^!?*\\] 

在建立索引以及搜索时进行删除。

关于elasticsearch - Elasticsearch edgeNGram分析器/ token 器模糊查询匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44777226/

相关文章:

elasticsearch - 带有 docker-compose 的 ELK 的推荐 RAM 比率

iOS - 检测和分析正在另一个应用程序中播放的音乐?

elasticsearch - 使用自定义分析器的Elasticsearch.js分析器错误

带有词干分析器的 Lucene Highlighter

elasticsearch - 如何使用elasticsearch ruby​​在附件管道中使用文档?

mysql - 存储和索引 1M+ XML 文档的最佳实践?

elasticsearch - Elasticsearch中的总结

python - 违反了 CPython 中的字符串不可变性

algorithm - 比较两个数据结构的相似性

matlab - 如何在 Matlab 中将数据保存在 "opts = statset(' Display' ,'iter' );”显示的文件或矩阵中?