Solr – Fields:
In this tutorial, we will learn about the Fields and Field types in Solr.
A piece of information which is related to particular type of data within a document can be identified as Field. Fields in Solr are like same as fields in RDBMS. In Solr, we can understand now data is stored in documents in the form of fields which are having very specific information within each.
Below is the example of Fields for a document Employee:
emp_firstname emp_Lastname emp_salary emp_mobile emp_city
How can Solr identify the type of data in a field?
That information can be served to Solr by using the field type. Let’s take the above example where emp_firstname holds a character type of data and emp_salary holds the integer type of data. So, it’s all about the type of data we are specifying to a field that tell the Solr how to interpret that information contained in that field.
Processing of the data during the time of indexing of any particular field in a document can be understood as field analysis.
Let us say there is a product description field of a document “product” which consist the information about a product and its features. If you want to query or search for wireless products by using the word WIRELESS, Solr will search through all the fields and breaks the words in those fields and identify the word wireless where ever it is and return the list of results.
Fields are defined in a file named schema.xml. Let’s take an example of defining a field called Grade which carries floating type of data.
<field name="price" type="float" default="0.0" indexed="true" stored="true"/>
Name of the field
Type of the field
Default value will be added automatically when there is no value in the field when it is indexed.
If this is true, the value of the field can be used to retrieve matching documents. Default value will be true.
If this is true, the actual value of the field can be retrieved by queries. Default value will be true.
In Solr, we can maintain the copies of fields where the two fields will have the same content which also stored in the index differently.
<copyField source="name" dest="text" maxChars="10000" />
Note: mentioning that fields need to be configured with multivalued=”true”
Dynamic fields are the one which can be indexing even though you don’t defined in your schema.
<dynamicField name="*_grade” type="float" indexed="true" stored="true"/>
We used the dynamic field “*_grade” in the schema. So that when we try to index final_grade field, which does not defined in the schema, then final_grade will get assigned the field type and analysis defined for *_score.