电子邮件未在Elasticsearch中正确搜索
您好,我是 Elasticsearch 的新手,我遇到了电子邮件搜索无法正常工作的问题我正在使用 boto3 SDK,并且 AWS opensearch 服务已尝试此映射,
{
"dev_auth0_logs_new_mapping": {
"mappings": {
"properties": {
"activity_date": { "type": "date" },
"activity_type": { "type": "text" },
"client_id": { "type": "text" },
"description": { "type": "text" },
"event_data": { "type": "object", "enabled": false },
"user_email": {
"type": "text",
"fields": { "keyword": { "type": "keyword" } }
},
"user_id": { "type": "text" }
}
}
}
}
这是我的查询
{
"from": 0,
"size": "10",
"track_total_hits": true,
"_source": [
"user_email",
"user_id",
"activity_date",
"activity_type",
"description",
"client_id",
"id"
],
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*[email protected]*",
"default_field": "user_email",
"default_operator": "OR"
}
}
]
}
},
"sort": [{ "activity_date": "desc" }]
}
,它无法与完全匹配一起工作 例如:-ashutosh.pandya 它正在返回结果,但对于 [电子邮件受保护] 它没有返回结果 我也关注了这个博客 medium 博客 并创建了使用自定义电子邮件分析器的新映射对我来说不起作用我不知道我做错了什么
我尝试过此查询来获取来自 [email protected] 但没有得到任何点击,
{
"from":0,
"size":"10",
"track_total_hits":True,
"_source":[
"user_email",
"user_id",
"activity_date",
"activity_type",
"description",
"client_id",
"id"
],
"query":{
"bool":{
"must":[
{
"query_string":{
"query":"*[email protected]*",
"default_field":"user_email",
"default_operator":"OR"
}
}
]
}
},
"sort":[
{
"activity_date":"desc"
}
]
}
但是当我搜索此查询时
{
"from":0,
"size":"10",
"track_total_hits":True,
"_source":[
"user_email",
"user_id",
"activity_date",
"activity_type",
"description",
"client_id",
"id"
],
"query":{
"bool":{
"must":[
{
"query_string":{
"query":"*ashutosh.pandya*",
"default_field":"user_email",
"default_operator":"OR"
}
}
]
}
},
"sort":[
{
"activity_date":"desc"
}
]
}
,我得到了其中的所有点击user_email 包含 ashutosh.pandya 我想要这个:- 如果我搜索 ashutosh,我会得到用户 emali 包含 ashutosh 的所有点击 如果我搜索 ashu,我会得到用户电子邮件包含 ashu 的所有点击 如果我搜索 pandya,我会得到用户电子邮件包含 pandya 的所有点击 如果我搜索 [email protected] 我得到了用户电子邮件相同的所有点击到[电子邮件受保护] 如果我搜索域名,我会得到用户电子邮件包含域名的所有点击
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要用于通配符匹配的自定义分析器。您实际上根本不需要将电子邮件拆分为令牌,因此在映射中使用
keyword
类型作为email
或使用email.keyword
搜索时。You don't need a custom analyzer for wildcard matches. You don't really need your email to be split into tokens at all so use
keyword
type foremail
in the mapping or useemail.keyword
when searching.我通过创建模式捕获令牌过滤器解决了这个问题
这是文档链接
i have solved this issue by creating a pattern capture token filter
this is the document link elasticsearch pattern capture token filter