Anumoy Sutradhar
Anumoy Sutradhar

Reputation: 543

What is the Solr field type for storing JSON object?

I want to store Json data as a value to an field, currently I have tried keeping that field type as string or text, which is fine but the Json is stored in string and hence the double quotes(") are escaped inside that, so what field type need to be kept for Json Object ?

Eg, suppose my field is Thumbnail and it should be stored and display as json object instead of string like below

"Thumbnail": {
              "Url":    "http://www.example.com/image/481989943",
              "Height": 125,
              "Width":  "100"
          }

Upvotes: 5

Views: 9775

Answers (2)

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

You can store it as String. The issue you are facing - I assume - is when you want to return that JSON as structure within the Solr JSON response. By default Solr does not know that you want to embed the content rather than present it.

To tell it otherwise, try using a [json] document transformer in your fl parameter.

Upvotes: 8

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

String type 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.). More of use when you want to match a word which is part of that a sentence.

With the text you can use tokenizers and filter made available by solr in order to create more useful token in order have proper search.

I would suggest to store it as the text.

It would be helpful for you to tokenize the data and can be helpful in the search as well.

Also as its a Json, it would be bigger in size and may grow bigger in size, so again can be helpful to be stored as text instead of string.

Upvotes: 0

Related Questions