elasticsearch - 比赛未能通过Elasticsearch

标签 elasticsearch match analyzer

我有以下索引,其中索引了邮件地址。

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/

相关文章:

具有两个输出标记的 Elasticsearch 自定义分析器

elasticsearch - ElasticSearch中的分析器不起作用

Xcode 分析器提示 CFContextRef 存储在 "assign"@property 中

elasticsearch - elasticsearch通配符索引类型

Elasticsearch 7.4 错误地提示快照已经在运行

使用 R 中另一个数据帧的其他匹配 ID 替换数据帧中的值

Haskell:两个整数列表之间的匹配次数?

angular - Elasticsearch 和 Angular 2

elasticsearch - 当至少一个对象不包含必要字段时,按对象数组选择文档 Elasticsearch

opencv - 为什么 OpenCV 中 BFMatcher::match() 不对称?