Adding a new field type
Add the Solr field type definitions to the search index schema, and then use the new type.
Procedure
-
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'];
-
Change the type of the field:
ALTER SEARCH INDEX SCHEMA ON [keyspace_name.]table_name SET field[@name='column_name']@type='fieldtype_name';
If a field name in the schema matches a table column, the column is indexed.
-
Verify the pending changes:
DESCRIBE PENDING SEARCH INDEX SCHEMA ON [keyspace_name.]table_name;
-
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.
-
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
.
-
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';
-
Change the gender field type:
ALTER SEARCH INDEX SCHEME ON demo.health_data SET field[@name='gender']@type='StrField';