我在尝试使用查询字符串搜索特殊字符时遇到了麻烦。我需要搜索格式为“ xxx@xxx.xxx”的电子邮件地址。在索引时,我使用了自定义规范化器,该规范化器提供小写和ascii折叠。在搜索时,我使用了一个自定义分析器,该分析器为空白提供了标记器,并提供了适用于小写和ascii折叠的过滤器。顺便说一下,我无法搜索简单的电子邮件地址。
这是我的地图
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1,
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
},
"normalizer": {
"lowerasciinormalizer": {
"type": "custom",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "keyword",
"normalizer": "lowerasciinormalizer"
}
}
}
这是我的搜索查询
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "pippo@pluto.it",
"fields": [
"email"
],
"analyzer": "folding"
}
}
]
}
}
}
不带特殊字符的搜索效果很好。实际上,如果我执行“查询”:“ pippo *”,我会得到正确的结果。 我还测试了令牌生成器的功能
GET /_analyze
{
"analyzer": "whitespace",
"text": "pippo@pluto.com"
}
我得到了我所期望的
{
"tokens" : [
{
"token" : "pippo@pluto.com",
"start_offset" : 0,
"end_offset" : 15,
"type" : "word",
"position" : 0
}
]
}
有什么建议吗? 谢谢。
编辑: 我正在使用Elasticsearch 7.5.1
此方法正确。我的问题在其他地方。