Add field to solr schema.xml

I use solr to search my database and try to add a new field (article publisher_id) in conf / schema.xml to get the value publisher_id after doing a search in my database, I didn’t find the field name equivalent to this field. so how can I add it as a field in schema.xml to return with the desired values ​​(body, title, date and publisher_id) of the article?

+8
field solr
source share
2 answers

First of all: what data is stored in publisher_id? If it is a number (int, log), add a field with the appropriate type, for example:

<field name="publisher_id" type="int" indexed="true" stored="true" /> 

After adding the field to schema.xml you need to restart the solr instance and rebuild your index.

+9
source share

Note that dynamic field additions were added in Solr 4.4 and Solr 5.0 ... none of them have yet been released.

In the meantime, if you want to add a field to your index, you have two options. First, you can make the hard way: add a field to your schema, clear your index, restart Solr and flip everything. This tends to be a little bankrupt.

Alternatively, you can use a dynamic field declaration . If you look in the diagram, you will see lines like these:

 <dynamicField name="*_i" type="int" indexed="true" stored="true"/> <dynamicField name="*_is" type="int" indexed="true" stored="true" multiValued="true"/> 

This means that if you add a field with a name ending in _i or _is , you will all be ready. They are usually included in the default schema, so if you have the flexibility of what to call in the field, you can be customized with this.

If none of these options looks promising, your third option is to wait for Solr 4.4 or 5.0 and the update (which will also have a reindex in all likelihood!).

+2
source share

All Articles