Adding a new field 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>';

    If a field name in the schema matches a table column, the column is indexed.

  1. Verify the pending changes:

    DESCRIBE PENDING SEARCH INDEX SCHEMA ON [<keyspace_name>.]<table_name>;
  2. 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.

  3. 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';

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com