Adding a new field type

Add the Solr field type definitions to the search index schema, and then use the new type.

Add the Solr field type definitions to the search index schema, and then use the new type.

Procedure

  1. Add the field type definition if it does not exist:
    ALTER SEARCH INDEX SCHEMA ON [keyspace_name.]table_name
     ADD types.fieldtype[@class='field_class', @name='type_name'];
  2. Change the type of the field:
    ALTER SEARCH INDEX SCHEMA ON [keyspace_name.]table_name
    SET field[@name='column_name']@type='fieldtype_name';
    Note: If a field name in the schema matches a table column, the column is indexed.
  3. Verify the pending changes:
    DESCRIBE PENDING SEARCH INDEX SCHEMA ON [keyspace_name.]table_name;
  4. Activate the changes:
    RELOAD SEARCH INDEX ON [keyspace_name.]table_name;
    Copies the pending schema over the active schema. New transactions, such as data inserted into the table, are processed using the active schema. The existing data is not effected by a schema change.
  5. Rebuild the index:
    REBUILD SEARCH INDEX ON [keyspace_name.]table_name;
    The REBUILD SEARCH INDEX regenerates the index using existing data. Rebuilding is required when changing the way that data is indexed, such as changing the type of field or if a field is added to the index.

Example

To run a faceted queries using the gender field, change the type to StrField.
  1. Add the Solr string field type to the health_data table:
    ALTER SEARCH INDEX SCHEMA ON demo.health_data 
    SET types.fieldtype[@class='org.apache.solr.schema.StrField']@name='StrField';
  2. Change the gender field type:
    ALTER SEARCH INDEX SCHEME ON demo.health_data
    SET field[@name='gender']@type='StrField';
    See Adding a column to the index.