Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr: what are the default values for fields which does not have a default value explicitly set?

Tags:

solr

lucene

I'm working with Solr's schema.xml, and I know that I can use the 'default' attribute to specify a default value which is to be used if a value for a given field has not been provided. However, say that I choose not to set the 'default' attribute, which default value will Solr then fall back to?

I would think that the field type which I've used for the given field would have a default value which would be used, but I have had not success finding any details about this. Alternatively, I'd think that not providing a value and not setting a default value effectively would be as if that field does not exist for the particular document.

However, I'm not sure and I'd like to know :-)

UPDATE 1

As far as I can see, Solr just throws an error and returns an error 400 "Bad Request" if no default value has been set and no value has been provided for a given field. In other words, Solr does not seem to apply any "fallback" default values in case no value is provided and no default value has been set in schema.xml.

UPDATE 2

My above update seems to be wrong. If no value has been provided for a field and no default value has been set for that field, then Solr will just treat the field as if it does not exist for that particular document. This behaviour does, of course, not apply if the field is required.

like image 429
sbrattla Avatar asked Dec 12 '22 09:12

sbrattla


1 Answers

If you don't supply value for field during indexing, solr will use default value as defined in schema.xml file. If default is not defined, solr ignores this field. If field is marked as required in schema.xml - solr will reject this document with error.

Example:

<field name="comments" type="text" indexed="true" stored="true" required="true"/>
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" />
like image 126
negativ Avatar answered Jun 08 '23 03:06

negativ