Dropping columns from the index

Remove a CQL column using the ALTER SEARCH INDEX SCHEMA field shortcut. The field is removed based on the name that is defined in the schema.

Procedure

  1. Remove a CQL column from the index:

    • Remove a regular column:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP field intfield;
      
      ALTER TABLE wiki.solr
      DROP intfield int;
    • Remove a tuple column from the index:

      When dropping the base field name, drop the TupleField and all the child fields:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP field fieldname;

      To drop individual child fields:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP field "fieldname.field1";
    • Remove a field that contains an asterisk in the name:

      To remove a field that contains an asterisk in the name, enclose the field name in double quotation marks:

      ALTER SEARCH INDEX SCHEMA
      ON wiki,solr
      DROP field "fieldname*";

      Alternatively, use the long form of the command:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP fields.field[@name='fieldname*'];
    • Remove a field that contains an incorrect XML path:

      For example, assume a field was added with an incorrect XML path that is not nested inside the <fields> tag:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      ADD field[@name='fieldname', @type='StrField'];

      Example XML fragment showing that the new field is outside of the <fields> tag:

      <fields>
        ...
      </fields>
      <field name="fieldname" type="StrField"/>

      If you use the short form of the ALTER SEARCH INDEX SCHEMA command, the command returns an error because it is assumed that the field is nested inside of the <fields> tag in the XML:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP field fieldname;
      InvalidRequest: Error from server: code=2200 [Invalid query] message= \
        "The search index schema could not be updated because: \
        Cannot drop resource element fields.field[@name='fieldname'] \
        because it doesn't exist"

      To drop the field, use the long form of the ALTER SEARCH INDEX SCHEMA command:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP field[@name='fieldname'];
    • Remove a dynamic field:

      To remove a dynamic field, use the long form of the ALTER SEARCH INDEX SCHEMA command because the field name always contains an asterisk:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP fields.dynamicField[@name='fieldname*'];
    • Remove a copy field:

      To remove a copy field, use the long form of the `ALTER SEARCH INDEX SCHEMA`command because the source and destination fields must be specified:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP copyField[@source='sourcefieldname', @dest='destfieldname'];
    • Remove associated copy fields and resolve dependencies:

      If you attempt to remove a field that has an associated copy field, the ALTER SEARCH INDEX SCHEMA command returns an invalid request error:

      ALTER SEARCH INDEX SCHEMA
      ON wiki.solr
      DROP fields.dynamicField[@name='copyfieldname*'];
      InvalidRequest: Error from server: code=2200 [Invalid query] message= \
        "The search index schema is not valid because: \
        Can't load schema schema.xml: copyField dest :'copyfieldname*' \
        is not an explicit field and doesn't match a dynamicField."

      To remove the field, remove all of the underlying child elements first and then remove the field.

  2. Verify the pending changes:

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

  4. 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.

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