Using dynamic fields 

Use dynamic fields to index content in fields that are not explicitly defined by the schema and process multiple Solr fields. Use a generic prefix or suffix to reference the field. A common use case for dynamic fields is to identify fields that should not be indexed or to implement a schema-less index.

Using dynamic fields, you can index content in fields that are not explicitly defined by the schema. Using dynamic fields, you can also process multiple Solr fields the same way. Use a generic prefix or suffix to reference the field. A common use case for dynamic fields is to identify fields that should not be indexed or to implement a schema-less index.

In CQL-based Solr cores, the Solr schema fields that are dynamic and multivalued are not supported.

Best practices

  • Avoid or limit the use of dynamic fields.

    Lucene allocates memory for each unique field (column) name, so if you have a row with columns A, B, C, and another row with B, D, E, Lucene allocates 5 chunks of memory. For millions of rows, the heap is unwieldy.

  • Instead of using dynamic fields, use Copy fields instead and then perform queries against the combined field.
  • Use the FieldInputTransformer (FIT) API as an option.

To use a dynamic field

  • Include a Solr dynamic field in schema.xml.

    Name the field using wildcard at the beginning or end of the field. For example, an asterisk prefix or suffix in the field name in the schema designates a dynamic field.

    • dyna_*
    • *_s
  • In CQL, to define the map collection column, use the same base name (no asterisk) as you used for the field in the schema.xml.

    For example, use dyna_* in schema.xml and dyna_ for the name of the CQL map collection.

  • Use type text for the map key. For example:

    CREATE TABLE my_dynamic_table (
      . . .
      dyna_ map<text, int>,
      . . .
    );
  • Using CQL, insert data into the map using the base name as a prefix or suffix in the first component of each map pair. The format of the map using a prefix is:

    { prefix_literal : literal, prefix_literal : literal, . . . }

    For example, the CQL map looks like this:
    'dyn_' : {dyn_1 : 1, dyn_2 : 2, dyn_3 : 3}
    DSE Search maps the Solr dynamic field to a Cassandra map collection column, as shown in the advanced tutorial.