# Non-case sensitive search on termquery

**URL:** <https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 3:57pm UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389 "2017-01-31T15:57:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeyP](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@SergeyP](https://discuss.elastic.co/u/SergeyP)\
**Post date:** [January 31, 2017, 3:57pm UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389/1 "2017-01-31T15:57:29Z")

</div>

Hi There,

I have already designed an application which is using term queries on keywords and I found out search is case sensitive. The problem is that my keyword fields represent the data as well. That means, I want to search them with non-case sensitive search, from the other hand I do not want to explicitly set them as lowercase as I do not want to loose case information to display data properly.

Is the above possible to achieve with ES 5.1? If not, what is better from performance perspective: duplicate my keywords: one in lowercase for search and another in original case to display? Or switch to "match" query? Actually match query for searching, for instance "777" will return also "111777111" (in filter context), but I want to avoid that.

Thanks in advance for your help

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 1, 2017, 7:28am UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389/2 "2017-02-01T07:28:22Z")

</div>

Hi Sergey,

I think that in case using lowercase filter, \_source field still has original case information.  
So you can display the word in original format.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html)

My testing case in Elasticsearc 5.1.1 below.  
In 5.2.0, "normalizer" option has added in keyword datatype, so it will be more simple.

```
// create index include "tags" field with lowercase filter.

PUT test_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "sample_analyzer": {
          "type": "custom",
          "tokenizer": "keyword",
          "char_filter": [],
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "tags": {
          "type": "text"
          , "analyzer": "sample_analyzer"}
      }
    }
  }
}

// index data including uppercase charactor in "tags" field

PUT test_index/doc/1
{
  "tags": "Sample"
}

// search by lowercased term

GET test_index/_search
{
  "query": {
    "term": {
      "tags": {
        "value": "sample"
      }
    }
  }
}

// result ("tags" field in hits still has case information)

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "test_index",
        "_type": "doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "tags": "Sample"
        }
      }
    ]
  }
}

```

mnozawa

---

<div class="post-metadata">

**Author:** ![SergeyP](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@SergeyP](https://discuss.elastic.co/u/SergeyP)\
**Post date:** [February 3, 2017, 4:26pm UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389/3 "2017-02-03T16:26:33Z")

</div>

Thank you for reply, I have updated my ES to 5.2 and used normalizer, which is really easy to configure. Still I do not see any solution to make case-sensitive and non case-sensitive search on the same field (if you setup a normalizer with lowercase filter, you can not search this field without normalizer anymore), but I currently do not need to implement this scenario, probably in later versions we will see normalizers being dynamically added inside the search query

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 4, 2017, 5:31pm UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389/4 "2017-02-04T17:31:04Z")

</div>

FYI

In case using one field for two way (like case-sensitive and case insensitive), _fields_ is useful 👍  
[https://www.elastic.co/guide/en/elasticsearch/reference/master/multi-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/multi-fields.html)

---

<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:** [March 4, 2017, 5:31pm UTC](https://discuss.elastic.co/t/non-case-sensitive-search-on-termquery/73389/5 "2017-03-04T17:31:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
