# Best practice of case insensitive keyword mapping in ES 5.x

**URL:** <https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015>\
**Category:** Elasticsearch\
**Created:** [February 6, 2017, 7:10am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015 "2017-02-06T07:10:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 6, 2017, 7:10am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/1 "2017-02-06T07:10:57Z")

</div>

In my old ES 2.x index mapping, I had a custom analyzer to support case insensitive keyword search:

```auto
{
  "settings": {
      "analyzer": {
        "lowercase_keyword": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      }
  },
  "mappings": {
    "type": {
      "properties": {
        "city": {
          "type": "string",
          "analyzer": "lowercase_keyword"
        }
      }
    }
  }
}

```

Now in ES 5.x, string is replaced with "text" and "keyword", then I have two options to implement case insensitive mapping.

1. Use same lowercase\_keyword analyzer approach as in ES 2.x, but change "string" to "text" in field mapping
2. Use new "keyword" type with new normalizer concept as follows:

```auto
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "type": {
      "properties": {
        "city": {
          "type": "keyword",
          "normalizer": "lowercase_normalizer"
        }
      }
    }
  }
}

```

Which one is better? From functionality point of view, I think no difference. I am wondering whether there is performance difference between these two approaches?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 6, 2017, 11:02am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/2 "2017-02-06T11:02:30Z")

</div>

There should be no difference in terms of search.

Aggregations is a different story as the `text` field would have to use heap-based FieldData (disabled by default) whereas `keyword` would use disk-based DocValues (generally recommended for analytic use cases).

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 7, 2017, 12:51am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/3 "2017-02-07T00:51:15Z")

</div>

So, in ES 5.x, no difference on both search and aggregation, since %S 5.x by default use doc value for text field, right?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 7, 2017, 9:26am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/4 "2017-02-07T09:26:23Z")

</div>

> [@Youxu](#):
>
> since %S 5.x by default use doc value for text field, right?

Untrue. DocValues are the default for `keyword` fields but are not supported for `text`

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 8, 2017, 1:12am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/5 "2017-02-08T01:12:12Z")

</div>

Thanks clarification!

---

<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 8, 2017, 1:12am UTC](https://discuss.elastic.co/t/best-practice-of-case-insensitive-keyword-mapping-in-es-5-x/74015/6 "2017-03-08T01:12:26Z")

</div>

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