你好,我是弹性搜索的新手,我在电子邮件搜索方面遇到问题,无法正常工作,我正在使用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": "*ashutosh.pandya@domain.com*",
"default_field": "user_email",
"default_operator": "OR"
}
}
]
}
},
"sort": [{ "activity_date": "desc" }]
}
它不适用于完全匹配例如:ashutosh.pandya它正在返回结果,但对于ashutosh.pandya@domain.com它不会返回结果我关注了这个博客,也关注了媒体博客,并用自定义电子邮件分析器创建了新的映射,它对我不起作用,我不知道我做错了什么
我已尝试此查询以从中获取所有日志ashutosh.pandya@domain.com但没有得到任何命中
{
"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@domain.com*",
"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的所有点击如果我搜索ashutosh.pandya@domain.com我得到了所有点击用户电子邮件等于ashutosh.pandya@domain.com如果我搜索域,我得到了用户电子邮件包含域的所有点击
您不需要自定义通配符匹配分析器。您根本不需要将电子邮件拆分为令牌,所以在映射中使用keyword
类型作为email
,或者在搜索时使用email.keyword
。
我通过创建模式捕获令牌过滤器解决了这个问题这是文档链接弹性搜索模式捕获令牌过滤器