# Indexing emails that come in uppercase, won't match lowercase searches

**URL:** <https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080>\
**Category:** Elasticsearch\
**Created:** [July 7, 2015, 7:43pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080 "2015-07-07T19:43:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 7, 2015, 7:43pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/1 "2015-07-07T19:43:06Z")

</div>

So I created this analyzer:

```
"uax_url_email" : {
     "filters" : [
        "standard",
        "lowercase",
        "stop"
     ],
     "type": "custom",
     "tokenizer" : "uax_url_email"
  }

```

And my mapping for the given field uses it:

```
        "email": {
          "type": "string",
          "analyzer": "uax_url_email"
        }

```

When my document are indexed, most of them actually come in with the email value beign uppercased. I didn't think this should really be an issue because when I search I can lowercase the term(s).

The problem is that if I do a search, it will only match if the term is cased as it was in the document - i.e. if the document had an uppercased email, it will only match if I provide the uppercased email in the search:

```
post candidate/main/_search
{
  "query": {
    "term" : {
      "email" : "MATCHES@GMAIL.COM"
    }
  }
}

```

The above would return a value because it's uppercased, but if I issue the same search as 'matches@gmail.com', nothing is returned.

Am I doing something wrong? The lowercase filter from the analyzer means the indexed terms should all be lowercased but tokenized as emails (per the uax tokenizer), but the searches seem to require the same case as the original document.

I have some good experience with Lucene but this is my first foray into ElasticSearch. I'm using 1.6.0.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 7, 2015, 8:09pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/2 "2015-07-07T20:09:44Z")

</div>

A first guess is that your mapping has not been applied.

May be you could reproduce it with a script so we can tell what's wrong...

---

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 7, 2015, 8:16pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/3 "2015-07-07T20:16:38Z")

</div>

This is a brand new index. I have deleted/recreated the index a few times, verifying the mappings & settings, and repopulating with my test records.

The sequence I'm running is right here:

```
DELETE my_index
PUT my_index
POST my_index/_close
PUT my_index/_settings
{
  "analysis" : {
    "analyzer" : {
      "email_analyzer" : {
         "filters" : [
            "lowercase"
         ],
         "type": "custom",
         "tokenizer" : "uax_url_email"
      }
    }
  }
}
POST my_index/_open
PUT my_index/main/_mapping
{
  "properties": {
	"email": {
	  "type": "string",
	  "analyzer": "email_analyzer"
	}
  }
}

```

It's pretty confusing ☹

edit: since my post here I did adjust to remove the standard and stop filters, which didn't do anything to help me, but that's why it's a bit different from my earlier post

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 7, 2015, 8:37pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/4 "2015-07-07T20:37:00Z")

</div>

Then? How do you index?

Note: don't close/open the index. The first PUT index can contain your settings.

---

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 7, 2015, 8:44pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/5 "2015-07-07T20:44:51Z")

</div>

I have a Java application as populating the index with some documents including email addresses. The emails that come in are uppercase.

The analyzer is supposed to standardize the indexed terms correct? My expectation was that with the lowercase filter in my email\_analyzer that the searchable terms would be lowercase.

So no matter what I'd expect to search using lowercase values, possibly with an analyzer specified in the querybuilder object.

But when I do a search it is only returning if I search with uppercase. That is to say it seems like the search on the email address is case sensitive.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 7, 2015, 9:00pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/6 "2015-07-07T21:00:51Z")

</div>

You could use \_analyze API to check which tokens are produced by the analyzer.

---

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 8, 2015, 12:40am UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/7 "2015-07-08T00:40:04Z")

</div>

it comes out like this:

```
{
  "tokens" : [ {
    "token" : "TEST@EMAIL.COM",
    "start_offset" : 0,
    "end_offset" : 20,
    "type" : "<EMAIL>",
    "position" : 1
  } ]
}

```

I'm not really sure what I'm looking at.

This is a full test case:

```
PUT my_index
{
  "analysis" : {
    "analyzer" : {
      "email_analyzer" : {
         "filters" : [
            "lowercase"
         ],
         "type": "custom",
         "tokenizer" : "uax_url_email"
      }
    }
  }
}

PUT my_index/main/_mapping
{
  "properties": {
  	"email": {
  	  "type": "string",
  	  "analyzer": "email_analyzer"
  	}
  }
}

PUT my_index/main/1
{
  "email" : "TEST@EMAIL.COM"
}

/* this returns the document */
GET my_index/main/_search 
{
  "query": {
    "match": {
      "email": "TEST@EMAIL.COM"
    }
  }
}

/* this does NOT return the document */
GET my_index/main/_search 
{
  "query": {
    "match": {
      "email": "test@email.com"
    }
  }
}

```

Just trying to figure out what, if anything, I'm doing wrong.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 8, 2015, 1:04am UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/8 "2015-07-08T01:04:02Z")

</div>

Got it!

Replace filters by filter 😄

PUT my\_index  
{  
"analysis" : {  
"analyzer" : {  
"email\_analyzer" : {  
"filter" : [  
"lowercase"  
],  
"type": "custom",  
"tokenizer" : "uax\_url\_email"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 8, 2015, 1:59am UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/9 "2015-07-08T01:59:59Z")

</div>

:facepalm:

thanks!

---

<div class="post-metadata">

**Author:** ![ronchalant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronchalant/32/3611_2.png) [@ronchalant](https://discuss.elastic.co/u/ronchalant)\
**Post date:** [July 8, 2015, 12:44pm UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/10 "2015-07-08T12:44:22Z")

</div>

It did work the way I expected after that change. Elastic has been real good about letting me know about malformed requests I didn't think to look for a typo.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:02am UTC](https://discuss.elastic.co/t/indexing-emails-that-come-in-uppercase-wont-match-lowercase-searches/25080/11 "2017-07-06T00:02:53Z")

</div>


