How to define new fields in schema.xml

Written by: Open Solr Administrator


So many people want to know how to add new fields in schema.xml
First of all here is a reference for the useful things you need to know before editing your schema.xml file
Here is a list of all field types that are included in solr by default.
Also, the field types may have certain filters and analyzers applied to them.
Here's the documentation about all filters and analyzers that solr supports by default
In your opensolr account, you have your collection management area where you can edit the schema.xml
The URL for that looks something like:[YOUR_OPENSOLR_COLLECTION_NAME]
On that page, click on the tab: Edit schema.xml
Now, in order to define new fields in schema.xml, all you have to do is scroll down in the schema.xml file, to the tag:
...fields are defined here...
Normally, this is line number 235 in schema.xml
You will then see some fields that are already defined in there:
<field name="id" type="string" indexed="true" stored="true" required="true" /> 
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="spell" type="spell" indexed="true" stored="true" multiValued="true"/>
And you also see some dynamic fields defined.
What you should do, is add / edit the fields that are defined above the dynamic fields to match those that are in your database.
You could remove the dynamic fields or leave them in. They do not influence your other fields.
For instance you could define a new field called "full_name" inside the <fields> tag like this:
<field name="full_name" type="text_general" indexed="true" stored="true" />
Please also note the type of the fields.
The type used for generic text fields, is text_general.
You can however define lots of other field types as well.
For instance here are some other types:
string - for exact string matches in search
int - for storing integers
tint - for storing tokenized integers that help with performing range searches For example: if the age field is of type tint:
<field name="age" type="tint" indexed="true" stored="trie" />
you could run your query like:
http://SOLR_SERVER_IP/solr/maxi24us/select?q=age:[13 TO *] 
And this will return all records that have the age greater than 13.
This can be applied for other fields as well.
In the same manner you can perform range queries on decimal fields by using the field types:
tdouble or tfloat
You can find all the field types in the schema.xml file inside the tag:
...all field types...