Chewy (Elasticsearch) -多个邮件与uax_url_email



我有一个简单的电子邮件分析器

analyzer: {
email: {
tokenizer: 'uax_url_email',
filter: ['lowercase']
}
}

和一个包含多个email值的字段:

field :emails,
type: :text,
analyzer: 'email',
search_analyzer: 'email',
value: -> (user) { [user.email, user.lead_requests.pluck(:email)].flatten.compact.uniq }

索引后,我试图找到它,我需要找到它的部分电子邮件:

UsersIndex.query(wildcard: { emails: "*example.com" }).count
=> 1

但是用@:

UsersIndex.query(wildcard: { emails: "*@example.com" }).count
=> 0

通配符不能用于完整的电子邮件:

UsersIndex.query(wildcard: { email: "volk@example.com" }).count
=> 0

只匹配完整的值:

UsersIndex.query(match: { emails: "volk@example.com" }).count
=> 1

似乎uax_url_email没有像预期的那样工作。

我应该怎么做,使包含搜索工作?

我认为你在字段或索引名称上犯了一些错误,它对我来说是有效的,如果你能像下面这样提供JSON格式的数据来确认

索引映射和设置

{
"settings": {
"analysis": {
"analyzer": {
"email": {
"type": "custom",
"tokenizer": "uax_url_email",
"filter": [
"lowercase"
]
}
}
}
},
"mappings" : {
"properties" : {
"mail" : {
"type" : "text",
"analyzer" : "email",
"search_analyzer": "email"
},
"mail_keyword": {
"type" : "keyword"
}
}
}
}

索引样本数据

{
"mail" : "abd@example.com"
}

通配符搜索查询

{
"query" : {
"wildcard" : {
"mail" : "abd@example.com" (note exact same mail which I indexed)
}
}
}

和搜索结果

"hits": [
{
"_index": "wildcard_test",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"mail": "abd@example.com"
}
}