SOLR 4.10.2 - Add field with default value

Viewed 141

I have a SOLR Core 4.10.2

I want to add a field VehicalType with an index IDX_VehicalType with a default value of "car" for all rows in the core. - I want this field populated with "car"

I have been able to add the field and index successfully using the following in the schema.xml and Reloading the core from from Core Admin:

<field name="IDX_VehicleType" type="text_Exact" indexed="true" stored="false" multiValued="true"/>
<field name="VehicleType" type="string" indexed="true" stored="true"/>
<copyField source="VehicleType" dest="IDX_VehicleType"/>

When I try to give the field a default using the default attribute - and reload, and optimize the core from Core Admin, the field is not populated.

<field name="IDX_VehicleType" type="text_Exact" indexed="true" stored="false" multiValued="true" default="car"/>
<field name="VehicleType" type="string" indexed="true" stored="true" default="car"/>
<copyField source="VehicleType" dest="IDX_VehicleType"/>

I see the field in the schema browser, but its not showing up in the results.

1 Answers

This change falls under the category of changes which need reindexing in SOLR to reflect the value in the field. To repeat, if we want to fill in the field with the default value for existing documents in the index, we would need to reindex all the docs in the index.

And for any future add/updates to the index, the default field value would be auto set by SOLR according to the new schema.

More on this: https://solr.apache.org/guide/8_0/reindexing.html#changing-field-and-field-type-properties https://solr.apache.org/guide/8_0/defining-fields.html#field-properties

Related