1

I have the following index in which I index mail addresses.

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"
        }
      }
    }
}

My e-mail in the following form "example.elastic@yahoo.com". When i index them they get analysed like example.elastic@yahoo.com, example.elastic, elastic, example.

When i run a match

GET _myindex/_search
{
    "query": {
        "match": {
            "email": "example.elastic@yahoo.com"
        }
    }
}

or using as a query string example, elastic, Elastic it works and retrieves results. But the problem is when I have "example.elastic.blabla@yahoo.com", it also returns the same results. What can be the problem?

Denisa Corbu
  • 301
  • 2
  • 16

1 Answers1

0

Using term query instead of match query will solve this.

Reason is, The match query will apply analyzer to the search term and will therefore match what is stored in the index. The term query does not apply any analyzers to the search term, so will only look for that exact term in the index.

Ref: https://stackoverflow.com/a/23151332/6546289

GET _myindex/_search
{
  "query": {
    "term": {
      "email": "example.elastic@yahoo.com"
    }
  }
}
KishanRSojitra
  • 267
  • 3
  • 17
  • The idea is that i also want Example.elastic@yahoo.com, or example, Example, Elastic, example.Elastic.. to match this, and using term, i cant achieve this. but thanks! – Denisa Corbu Jun 21 '18 at 10:33
  • 1
    I get it. As far as I know to achieve desired result with the same mapping you have to use script to filter the output. Or you can change the mapping. Changes to do in mapping: Add a keyword field in the mapping and use it when you have to get exact match. – KishanRSojitra Jun 21 '18 at 12:56