Fields

Fields are defined in the fields element of a schema. Once you have the field types set up, defining the fields themselves is simple.

Example Field Definition

The following example defines a field named price with a type named float and a default value of 0.0; the indexed and stored properties are explicitly set to true, while any other properties specified on the float field type are inherited.

<field name="price" type="float" default="0.0" indexed="true" stored="true"/>

Field Properties

Field definitions can have the following properties:

name

Required

Default: none

The name of the field. Field names should consist of alphanumeric or underscore characters only and not start with a digit. This is not currently strictly enforced, but other field names will not have first class support from all components and back compatibility is not guaranteed. Names with both leading and trailing underscores (e.g., _version_) are reserved.

type

Required

Default: none

The name of the fieldType for this field. This will be found in the name attribute on the fieldType definition. Every field must have a type.

default

Optional

Default: none

A default value that will be added automatically to any document that does not have a value in this field when it is indexed. If this property is not specified, there is no default.

Optional Field Type Override Properties

Fields can have many of the same properties as field types. Properties from the table below which are specified on an individual field will override any explicit value for that property specified on the fieldType of the field, or any implicit default property value provided by the underlying fieldType implementation. The table below is reproduced from Field Type Definitions and Properties, which has more details:

Property Description Implicit Default

indexed

If true, the value of the field can be used in queries to retrieve matching documents.

true

stored

If true, the actual value of the field can be retrieved by queries.

true

docValues

If true, the value of the field will be put in a column-oriented DocValues structure.

true for most fields

sortMissingFirst, sortMissingLast

Control the placement of documents when a sort field is not present.

false

multiValued

If true, indicates that a single document might contain multiple values for this field type.

false

uninvertible

If true, indicates that an indexed="true" docValues="false" field can be "un-inverted" at query time to build up large in memory data structure to serve in place of DocValues.

false

omitNorms

If true, omits the norms associated with this field (this disables length normalization for the field, and saves some memory). Defaults to true for all primitive (non-analyzed) field types, such as int, float, data, bool, and string. Only full-text fields or fields that need an index-time boost need norms.

*

omitTermFreqAndPositions

If true, omits term frequency, positions, and payloads from postings for this field. This can be a performance boost for fields that don’t require that information. It also reduces the storage space required for the index. Queries that rely on position that are issued on a field with this option will silently fail to find documents. This property defaults to true for all field types that are not text fields.

*

omitPositions

Similar to omitTermFreqAndPositions but preserves term frequency information.

*

termVectors, termPositions, termOffsets, termPayloads

These options instruct Solr to maintain full term vectors for each document, optionally including position, offset, and payload information for each term occurrence in those vectors. These can be used to accelerate highlighting and other ancillary functionality, but impose a substantial cost in terms of index size. They are not necessary for typical uses of Solr.

false

required

Instructs Solr to reject any attempts to add a document which does not have a value for this field. This property defaults to false.

false

useDocValuesAsStored

If the field has DocValues enabled, setting this to true would allow the field to be returned as if it were a stored field (even if it has stored=false) when matching “*” in an fl parameter.

true

large

Large fields are always lazy loaded and will only take up space in the document cache if the actual value is < 512KB. This option requires stored="true" and multiValued="false". It’s intended for fields that might have very large values so that they don’t get cached in memory.

false