How to Define New Fields in schema.xml

Configuration

Overview

The schema.xml file defines the structure of your Solr index — it tells Solr what fields exist, what type of data they hold, and how they should be analyzed during indexing and search. Understanding how to add and configure fields is essential for any Solr implementation.

Where to Edit schema.xml

In your Opensolr account, navigate to your index management area at:

https://opensolr.com/admin/solr_manager/tools/YOUR_INDEX_NAME

Click on the Edit schema.xml tab to open the schema editor.

Defining a New Field

Fields are defined inside the <fields> section of schema.xml. To add a new field, insert a <field> element with the appropriate attributes:

<field name="full_name" type="text_general" indexed="true" stored="true" />

Field Attributes Explained

  • name — The field name, used when indexing and querying documents.
  • type — The field type, which determines how data is analyzed and stored (see below).
  • indexed="true" — The field is searchable. Set to false if you only need to retrieve the value.
  • stored="true" — The original value is stored and can be returned in search results.
  • multiValued="true" — The field can hold multiple values (e.g., tags).
  • required="true" — A document cannot be indexed without this field (typically only used for the id field).

Common Field Types

TypeDescriptionUse Case
text_generalTokenized text with standard analysisFull-text search fields (titles, descriptions)
stringExact, untokenized stringIDs, categories, facets, filters
int / pintInteger valueCounts, quantities
tintTrie-based integer (legacy)Range queries on integers
tfloat / tdoubleTrie-based decimal numbersPrices, measurements, range queries
booleanTrue/false valueFlags, toggles
date / pdateDate/time in ISO 8601 formatTimestamps, date filtering

Example: Range Queries with Numeric Fields

If you define an integer field using a trie type, you can perform range queries. For example:

<field name="age" type="tint" indexed="true" stored="true" />

You can then query for all documents where age is greater than 13:

https://YOUR_SOLR_HOST/solr/YOUR_INDEX/select?q=age:[13 TO *]

The same principle applies to tfloat and tdouble fields for decimal range queries, such as filtering products by price.

Dynamic Fields

Your schema.xml also contains dynamic field definitions that use wildcard patterns. These automatically match any field name that fits the pattern:

<dynamicField name="*_s" type="string" indexed="true" stored="true" />
<dynamicField name="*_i" type="int" indexed="true" stored="true" />
<dynamicField name="*_t" type="text_general" indexed="true" stored="true" />

Dynamic fields let you index data without explicitly defining every field. For example, a field named color_s would automatically be treated as a string. You can leave these in place or remove them — they do not affect your explicitly defined fields.

Further Reading