# What options to set in mapping for string that's a JSON representation?

**URL:** <https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039>\
**Category:** Elasticsearch\
**Created:** [July 5, 2019, 8:28am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039 "2019-07-05T08:28:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [July 5, 2019, 8:28am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/1 "2019-07-05T08:28:18Z")

</div>

I have a field that's a JSON string representation and I don't need to sort or search on it. Is it correct that I should use `text` type instead of `keyword` type?

Which options should I set at [https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html) or [https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html) that would work for this situation? I think `index` should be set to `false`? But what about all the other options there like `analyzer` and the rest?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 5, 2019, 8:30am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/2 "2019-07-05T08:30:48Z")

</div>

You may want an `index: false` + keyword field.  
That way the analyser won't break it apart and there's no index created for the field.

---

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [July 5, 2019, 8:43am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/3 "2019-07-05T08:43:13Z")

</div>

If I set `index: false` on `keyword` then it's enough? And I don't need to disable the `analyzer` or change any other options in the mapping?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 5, 2019, 8:44am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/4 "2019-07-05T08:44:42Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html) - these are not analysed.

---

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [July 5, 2019, 8:49am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/5 "2019-07-05T08:49:49Z")

</div>

I see now that there's actually an `index` option on both `keyword` and `text` types. If you can disable indexing in both cases, what's the difference between `keyword` with `index: false` and `text` with `index: false`? What does one do that the other doesn't?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 5, 2019, 8:57am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/6 "2019-07-05T08:57:45Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html) and [https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html) are the best references.

---

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [July 5, 2019, 9:09am UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/7 "2019-07-05T09:09:37Z")

</div>

You mean the 2 links I put in my question? 🙂

I've read them but I'm just confused that when `index: false` is set on both of them I fail to see what the difference is between a field set as text with no indexing, and a field set as keyword with no indexing. If there's no index on both, then aren't they equivalent? You can't search or sort on either in that case right? So where do they differ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 5, 2019, 10:10pm UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/8 "2019-07-05T22:10:48Z")

</div>

Woops, sorry.

So the text field will be analysed, meaning if you have a sentence it's broken down into constituent words and have things like lowercase/stopwords applied, whereas a keyword will be retained entirely as it is.

When also applying index to false, then there's not a whole lot of difference as you can't/won't search on them. But you'd be better off using a keyword as you retain the original value and you don't do any non-needed work to it.

---

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [July 11, 2019, 3:05pm UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/9 "2019-07-11T15:05:13Z")

</div>

With a `text` field with `index: false`, what would be the purpose of the field still being analyzed/tokenized? Just curious, if it's not indexed couldn't elasticsearch just see `index: false` on `text` type and just not do any analysis/tokenization because what would be the purpose of doing so?

---

<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:** [August 8, 2019, 3:05pm UTC](https://discuss.elastic.co/t/what-options-to-set-in-mapping-for-string-thats-a-json-representation/189039/10 "2019-08-08T15:05:18Z")

</div>

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