68

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?

Ravindra S
  • 6,302
  • 12
  • 70
  • 108
Rahul
  • 1,403
  • 4
  • 18
  • 31

2 Answers2

131

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.

kidbrax
  • 2,364
  • 3
  • 30
  • 38
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
  • 1
    can you also comment on index size, index read, index creation? – Rahul Aug 25 '11 at 09:31
  • 5
    You will get a larger index size when tokenizing, how large depends on your processing chain. Index creation will also be marginally slower since there's more work. Index read/creation will be great either way, so don't worry about it unless approaching millions of documents. – Johan Sjöberg Aug 25 '11 at 09:37
  • 2
    I am reading through millions of documents..hope that is not a problem..so I am going for string field since it seems efficient in all cases AND I do not need tokenizers/full text search – Rahul Aug 25 '11 at 10:47
  • 2
    @JohanSjöberg I understand the difference between String and Text as you have explained it, but what if I need to get hits for `*tence `. What if the correct choice for field type? – dacracot Mar 11 '19 at 15:05
2

Adding to Johans Sjöbergs good answer:

You can sort a String but not a Text.

Jan Bühler
  • 421
  • 3
  • 18