1

确实尝试了弹性搜索文档和谷歌的一些示例,但没有任何帮助解决..

只是我拥有的示例数据只是几篇博客文章。我正在尝试查看所有带有电子邮件地址的帖子。当我使用时,"email":"someone"我看到所有匹配的帖子someone,但是当我更改为使用时,someone@gmail.com什么都没有出现!

    "hits": [
             {
                "_index": "blog",
                "_type": "post",
                "_id": "2",
                "_score": 1,
                "_source": {
                   "user": "sreenath",
                   "email": "someone@gmail.com",
                   "postDate": "2011-12-12",
                   "body": "Trying to figure out this",
                   "title": "Elastic search testing"
                }
             }
           ]

当我使用 Get 查询时,如下所示,我看到所有帖子匹配someone@anything.com。但我想把它 { "term" : { "email" : "someone" }}改成{ "term" : { "email" : "someone@gmail.com" }}

GET blog/post/_search
{ 
 "query" : { 
   "filtered" : { 
     "filter" : { 
       "and" : [ 
         { "term" :
            { "email" : "someone" }
         }
       ] 
     } 
   } 
 } 
}

我为以下内容做了 curl -XPUT,但没有帮助

curl -XPUT localhost:9200/test/  -d '
{
   "settings" : {
      "analysis" : {
         "filter" : {
            "email" : {
               "type" : "pattern_capture",
               "preserve_original" : 1,
               "patterns" : [
                  "([^@]+)",
                  "(\\p{L}+)",
                  "(\\d+)",
                  "@(.+)"
               ]
            }
         },
         "analyzer" : {
            "email" : {
               "tokenizer" : "uax_url_email",
               "filter" : [ "email", "lowercase",  "unique" ]
            }
         }
      }
   }
}
'
4

1 回答 1

1

您已经为电子邮件地址创建了一个自定义分析器,但您没有使用它。您需要email在映射类型中声明该字段才能实际使用该分析器,如下所示。还要确保使用该分析器创建正确的索引,即blog而不是test

                       change this
                            |
                            v
curl -XPUT localhost:9200/blog/  -d '{
   "settings" : {
      "analysis" : {
         "filter" : {
            "email" : {
               "type" : "pattern_capture",
               "preserve_original" : 1,
               "patterns" : [
                  "([^@]+)",
                  "(\\p{L}+)",
                  "(\\d+)",
                  "@(.+)"
               ]
            }
         },
         "analyzer" : {
            "email" : {
               "tokenizer" : "uax_url_email",
               "filter" : [ "email", "lowercase",  "unique" ]
            }
         }
      }
   },
   "mappings": {              <--- add this
      "post": {
         "properties": {
            "email": {
               "type": "string",
               "analyzer": "email"
            }
         }
      }
   }
}
'
于 2016-08-02T05:00:46.390 回答