gpt4 book ai didi

elasticsearch - Elasticsearch查询忽略空格

转载 作者:行者123 更新时间:2023-12-02 22:24:52 52 4
gpt4 key购买 nike

在Elasticsearch上,如何查询忽略空格的字符串属性?

该方案是将电话号码索引为具有不同格式的字符串。查询没有空格的电话,是否可以获取所有包含该电话的字符串(有无空格)。例如:

{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"must_not": [],
"should": []
}
},
"filter": {
"nested": {
"path": "Contacts",
"query": {
"query_string": {
"default_field": "Contacts.ContactValue",
"query": "261981255"
}
}
}
}
}

此查询将返回以下联系人:“261981255”,“261 981 255”,“26 19 81 25 5”等。

最佳答案

您需要使用特定的分析器,将查询分解为克。

您可以通过为您的字段设置映射search_analyzer来实现。

关于elasticsearch - Elasticsearch查询忽略空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682907/

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