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

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 or 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?

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.

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?

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

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?

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

You mean the 2 links I put in my question? :slight_smile:

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?

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.

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?

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