# Case insensitive search and doc\_values

**URL:** <https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011>\
**Category:** Elasticsearch\
**Created:** [June 27, 2016, 8:35am UTC](https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011 "2016-06-27T08:35:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haizaar](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@haizaar](https://discuss.elastic.co/u/haizaar)\
**Post date:** [June 27, 2016, 8:35am UTC](https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011/1 "2016-06-27T08:35:27Z")

</div>

I'm storing lots of keyword like strings in my ES 2.3.3. I treat them like terms meaning that I don't want to analyze them.

However I do want to perform **case-insensitive** term queries and aggregations. The only way I've found so far is to make these fields analyzed and use `keyword` analyzer with `lowercase` filter. This works fine, however I can not utilize `doc_values` any more. Is there a way to achieve case-insensitive search without loosing `doc_values` feature?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [June 27, 2016, 1:16pm UTC](https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011/2 "2016-06-27T13:16:20Z")

</div>

> [@haizaar](#):
>
> I treat them like terms meaning that I don't want to analyze them.

We call those `keyword`s after the analyzer.

> [@haizaar](#):
>
> Is there a way to achieve case-insensitive search without loosing doc\_values feature?

In 5.0 you'll be able to do it with the `keyword` field type. Before that you'll need to use `fields` inside the field like this:

```auto
"title": {
    "type": "string",
    "analyzer": "keyword_lowercase",
    "fields": {
        "raw": { "type": "string", "index": "not_analyzed" }
    }
}

```

Then you can use doc values on the `raw` field and search on the regular field. This means that doc values keep the original case but that might be ok for your use case. With the `keyword` field the doc values would all be lower case. If you used a lowercasing keyword analyzer.

---

<div class="post-metadata">

**Author:** ![haizaar](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@haizaar](https://discuss.elastic.co/u/haizaar)\
**Post date:** [June 27, 2016, 1:21pm UTC](https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011/3 "2016-06-27T13:21:46Z")

</div>

Yeah, I've thought about adding a `raw` field and use it for aggregation, and the lowercased field for search/filtering. This has the usual question of trade-off between RAM saved by using doc values and disk space "wasted" by storing the data twice. And it's hard to simulate, since I don't know what will be used more - searches or aggregations.

It's great we'll have the best of both worlds in ES 5.0. Thanks for good news!

Zaar

---

<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 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/case-insensitive-search-and-doc-values/54011/4 "2017-07-05T22:40:14Z")

</div>


