gpt4 book ai didi

java - Elasticsearch:按字母顺序排序,忽略数字和特殊字符

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:54 24 4
gpt4 key购买 nike

如何按字母顺序对文本字段进行排序,忽略特殊字符和数字?默认情况下,特殊字符在前,然后是数字和字母。

我需要的是字母应该排序并首先出现,然后是数字和特殊字符。这在 ES 6.3 中可能吗?

我尝试使用自定义分析器来替换所有非字母字符,但它不起作用:

{
"analysis": {
"analyzer": {
"alphabets_analyzer": {
"tokenizer": "standard",
"type": "keyword",
"char_filter": [
"alphabets_char_filter"
]
}
},
"char_filter": {
"alphabets_char_filter": {
"type": "pattern_replace",
"pattern": "[^a-zA-Z\\s\\.]",
"replacement": ""
}
}
}
}

最佳答案

我能够通过索引级别的以下设置解决此问题:

{
"analysis": {
"analyzer": {
"alphabetsStringAnalyzer": {
"tokenizer": "standard",
"filter": "lowercase",
"type": "custom",
"char_filter": [
"alphabets_char_filter"
]
}
},
"char_filter": {
"alphabets_char_filter": {
"type": "pattern_replace",
"pattern": "[^a-zA-Z]",
"replacement": ""
}
}
}
}

并在索引映射中设置此分析器,如下所示:

"fullName":{
"type": "keyword",
"fields": {
"raw": {
"type": "text",
"analyzer": "alphabetsStringAnalyzer",
"fielddata": true
}
}
}

关于java - Elasticsearch:按字母顺序排序,忽略数字和特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53871282/

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