gpt4 book ai didi

elasticsearch - 在elasticsearch中匹配带减号的字符串

转载 作者:行者123 更新时间:2023-12-04 03:41:57 25 4
gpt4 key购买 nike

所以在数据库中我有这个条目:

Mark-Whalberg

使用术语搜索时
Mark-Whalberg

我得到不匹配。

为什么?减号是我理解的特殊字符吗?它象征着“排除”?

查询是这样的:

{"query_string": {"query": 'Mark-Whalberg', "default_operator": "AND"}}

搜索其他所有内容,例如:
Mark
Whalberg
hlb
Mark Whalberg

返回匹配。

这是存储为两个不同的部分吗?在搜索词中包含减号时如何获得匹配项?

- - - - - - - 编辑 - - - - - - -

这是当前的查询:
var fields = [
"field1",
"field2",
];

{"query_string":{"query": '*Mark-Whalberg*',"default_operator": "AND","fields": fields}};

最佳答案

您有分析器配置问题。

让我解释一下。当您在 ElasticSearch 中定义索引时,您没有为该字段指定任何分析器。这意味着它是 Standard Analyzer这将适用。

根据documentation :

Standard Analyzer

The standard analyzer is the default analyzer which is used if none is specified. It provides grammar based tokenization (based on the Unicode Text Segmentation algorithm, as specified in Unicode Standard Annex #29) and works well for most languages.



另外,回答你的问题:

Why? Is minus a special character what I understand? It symbolizes "exclude"?



对于标准分析仪, 是的,它是 .它并不意味着“排除”,而是一个特殊的字符,将是 已删除 分析后。

来自 documentation :

为什么术语查询与我的文档不匹配?

[...] There are many ways to analyze text: the default standard analyzer drops most punctuation, breaks up text into individual words, and lower cases them. For instance, the standard analyzer would turn the string “Quick Brown Fox!” into the terms [quick, brown, fox]. [...]



示例:

如果您有以下文字:
"The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."

然后标准分析器将产生:
[ the, 2, quick, brown, foxes, jumped, over, the, lazy, dog's, bone ]

如果您不想使用分析仪,您有 2 个解决方案:
  • 您可以使用 match query .
  • 您可以在创建索引时要求 ElasticSearch 不分析该字段: here's how

  • 我希望这能帮到您。

    关于elasticsearch - 在elasticsearch中匹配带减号的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44043372/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com