我有以下索引,其中索引了邮件地址。
PUT _myindex
{
"settings" : {
"analysis" : {
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : true,
"patterns" : [
"^(.*?)@",
"(\\w+(?=.*@))"]
}
},
"analyzer" : {
"email" : {
"tokenizer" : "uax_url_email",
"filter" : [ "lowercase","email", "unique" ]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "text",
"analyzer": "email"
}
}
}
}
我的电子邮件格式为“example.elastic@yahoo.com”。当我将它们编入索引时,它们将得到分析,例如example.elastic @ yahoo.com,example.elastic,elastic,example。
当我进行比赛时
GET _myindex/_search
{
"query": {
"match": {
"email": "example.elastic@yahoo.com"
}
}
}
或使用Elastic作为查询字符串示例,Elastic可以工作并检索结果。但是问题是当我有“example.elastic.blabla@yahoo.com”时,它也会返回相同的结果。可能是什么问题?
最佳答案
使用term
查询代替match
查询将解决此问题。
原因是,匹配查询会将分析器应用于搜索项,因此将匹配存储在索引中的内容。字词查询不会将任何分析器应用于搜索字词,因此只会在索引中查找该确切字词。
引用:https://stackoverflow.com/a/23151332/6546289
GET _myindex/_search
{
"query": {
"term": {
"email": "example.elastic@yahoo.com"
}
}
}
关于elasticsearch - 比赛未能通过Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50962520/