Apache Solr string field or text field?

Solr

Solr Problem Overview


In apache Solr why do we always need to prefer string field over text field if both solves purposes?

How string or text affects the parameters like index size, index read, index creation?

Solr Solutions


Solution 1 - Solr

The fields as default defined in the solr schema are vastly different.

String stores a word/sentence as an exact string without performing tokenization etc. Commonly useful for storing exact matches, e.g, for facetting.

Text typically performs tokenization, and secondary processing (such as lower-casing etc.). Useful for all scenarios when we want to match part of a sentence.

If the following sample, "This is a sample sentence", is indexed to both fields we must search for exactly the text This is a sample sentence to get a hit from the string field, while it may suffice to search for sample (or even samples with stemmning enabled) to get a hit from the text field.

Solution 2 - Solr

Adding to Johans Sjöbergs good answer:

You can sort a String but not a Text.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahulView Question on Stackoverflow
Solution 1 - SolrJohan SjöbergView Answer on Stackoverflow
Solution 2 - SolrJan BühlerView Answer on Stackoverflow