Defining Fields
Fields are defined in the fields element of schema.xml
. 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
- 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. Every field must have aname
. type
- The name of the
fieldType
for this field. This will be found in thename
attribute on thefieldType
definition. Every field must have atype
. default
- 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 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 | Values | Implicit Default |
---|---|---|---|
indexed | If true, the value of the field can be used in queries to retrieve matching documents. | true or false | true |
stored | If true, the actual value of the field can be retrieved by queries. | true or false | true |
docValues | If true, the value of the field will be put in a column-oriented DocValues structure. | true or false | false |
sortMissingFirst sortMissingLast | Control the placement of documents when a sort field is not present. | true or false | false |
multiValued | If true, indicates that a single document might contain multiple values for this field type. | true or false | 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. Defaults to true for historical reasons, but users are strongly encouraged to set this to false for stability and use docValues="true" as needed. | true or false | true |
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 need norms. | true or false | * |
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. | true or false | * |
omitPositions | Similar to omitTermFreqAndPositions but preserves term frequency information. | true or false | * |
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. | true or false | 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. | true or 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 or false | 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. | true or false | false |