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:

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.

Field Analysis:

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.

Defining Fields:

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.

Example:

Name:

Name of the field

Type:

Type of the field

Default:

Default value will be added automatically when there is no value in the field when it is indexed.

Indexed:

If this is true, the value of the field can be used to retrieve matching documents. Default value will be true.

Stored:

If this is true, the actual value of the field can be retrieved by queries. Default value will be true.

Copying Fields:

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.

Example:

Note: mentioning that fields need to be configured with multivalued=”true”

Dynamic Fields:

Dynamic fields are the one which can be indexing even though you don’t defined in your schema.

Example:

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.