ALTER SEARCH INDEX SCHEMA

Modify the search index pending schema.

Use the RELOAD SEARCH INDEX command to apply changes to the active schema.

Space saving profiles apply only to the initial creation of the search index. For example, if the index was created using a resource_generation_profile, like spaceSavingSlowTriePrecision, and later a numeric column is added to the index using the ALTER command, the trie fields precisionStep of the new column is not set to '0'.

Restriction: Command available only on DSE Search nodes. Running search index management commands on large datasets can take longer than the CQLSH default timeout of 10 minutes. Increase the CQLSH client timeout as required.

Synopsis

ALTER SEARCH INDEX SCHEMA ON [<keyspace_name>.]<table_name>
  ( ADD <field column_name>
  | ADD <element_path> [ <attribute_list> ] WITH $$ <json_map> $$
  | SET <element_identifier> = '<value>'
  | DROP <field field_name>
  | DROP <element_identifier> ) ;
Syntax legend
Legend
Syntax conventions Description

UPPERCASE

Literal keyword.

Lowercase

Not literal.

< >

Variable value. Replace with a user-defined value.

[]

Optional. Square brackets ([]) surround optional command arguments. Do not type the square brackets.

( )

Group. Parentheses ( ( ) ) identify a group to choose from. Do not type the parentheses.

|

Or. A vertical bar (|) separates alternative elements. Type any one of the elements. Do not type the vertical bar.

...

Repeatable. An ellipsis ( ... ) indicates that you can repeat the syntax element as often as required.

'<Literal string>'

Single quotation (') marks must surround literal strings in CQL statements. Use single quotation marks to preserve upper case.

{ <key> : <value> }

Map collection. Braces ({ }) enclose map collections or key value pairs. A colon separates the key and the value.

<datatype2

Set, list, map, or tuple. Angle brackets ( < > ) enclose data types in a set, list, map, or tuple. Separate the data types with a comma.

<cql_statement>;

End CQL statement. A semicolon (;) terminates all CQL statements.

[--]

Separate the command line options from the command arguments with two hyphens ( -- ). This syntax is useful when arguments might be mistaken for command line options.

' <<schema\> ... </schema\>> '

Search CQL only: Single quotation marks (') surround an entire XML schema declaration.

@<xml_entity>='<xml_entity_type>'

Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files.

Variables
column_name

Identifies a table column. The search index field and associated type are automatically defined.

keyspace_name.table_name

Identifies the table of the search index; keyspace name is required when the table is not in the active keyspace.

element_path

Identifies the XML path to the setting. Separate child elements using a period. For example:

types.fieldTypes
attribute_list

A comma-separated list of attributes value pairs enclosed in braces using the following syntax:

[@<attribute_name> = '<value>',
@<attribute_name> = '<value>', ... ]
json_map

Advanced. Use JSON format to define child elements, such as analyzer tokenizer and filter definitions of field type.

{ "element_name" : [
                  { "child_element_name" : { "child_attribute_name" : "value" } } ,
                  { "child_element_name" : { "child_attribute_name" : "value" } }, ... ],
"element_name" : [
                  { "child_element_name" : { "child_attribute_name" : "value" } } ,
                  { "child_element_name" : { "child_attribute_name" : "value" } }, ... ], ... }
element_identifier

Identifies the XML path to the setting. To locate an element with specific attribute, use the following syntax.

<element_name>[@<attribute_name>='<value>']
ADD

Insert a new type, field, or other settings in the pending schema.

DROP

Remove a table column that corresponds directly to a field or one of the following configurations from the pending schema. The required attributes by element are:

SET

Change the configuration of a setting in the pending schema.

EBNF

EBNF syntax:

alterSearchIndex ::= 'ALTER' 'SEARCH' 'INDEX' 'SCHEMA'
          'ON' tableName
          (
          ('ADD' elementPath 'WITH' json) |
          ('ADD' 'FIELD' fieldName) |
          ('SET' elementPath('@' attribute)? '=' value) |
          ('DROP' elementPath('@' attribute)?) |
          ('DROP' 'FIELD' fieldName)
          )
          tableName        ::= (keyspace '.')? table
          elementPath      ::= elementName
          ('[' '@' attributeName '=' attributeValue
          (',' '@' attributeName '=' attributeValue)* ']')?
          ( '.' elementName ('[' '@' attributeName '=' attributeValue
          (',' '@' attributeName '=' attributeValue)* ']')?)*

Railroad diagram:

alterSearchIndex
Image shows the first part of a railroad diagram for the ALTER SEARCH INDEX search CQL command
Image shows the first part of a railroad diagram for the ALTER SEARCH INDEX search CQL command
tableName
Image shows a railroad diagram of tableName
elementPath
Image shows a railroad diagram of elementPath

Examples

The search index schema is altered for the cycling.comments keyspace and table, and the specified options.

For extensive information and examples on search indexes, including adding and dropping search index fields, field types, field classes, tuples, UDTs, and map columns, see Managing search index fields.

You must add the search index before you can alter it.

Add a new field using the element path and attribute list

Fields that do not exist in the table can be added to index to combine multiple columns into a single indexed field for searches.

Adding the leading element fields. in ADD fields.field fieldname is optional and provides only cosmetic structure.

  ALTER SEARCH INDEX SCHEMA ON cycling.comments 
    ADD fields.field[@name='fieldname', @type='StrField', @multiValued = 'false', @indexed='true'];

To apply the schema changes:

  RELOAD SEARCH INDEX ON cycling.comments;

Add a table column to the index

Automatically creates a field definition and adds the field type if required for a field that is not already indexed.

  ALTER SEARCH INDEX SCHEMA ON cycling.comments 
    ADD FIELD record_id;

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Change a field name

DSE maps CQL columns to search index fields by matching the column name to the field name. Use unmapped fields for copy fields. If the field does not already exist it is added.

  ALTER SEARCH INDEX SCHEMA ON cycling.comments 
    SET field[@name='fieldname']@name = 'anotherFieldName';

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Change the field type

Change the field type to another type that is already defined in the schema:

  ALTER SEARCH INDEX SCHEMA ON cycling.comments 
    SET field[@name='fieldname']@type = 'UUIDField';

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Drop a field

To remove a field from the search index, but not from the table:

  ALTER SEARCH INDEX SCHEMA ON cycling.comments 
    DROP field anotherFieldName;

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Set a field type and a text field

The first command sets the TextField type, which is required for the second command that sets the text field:

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    SET types.fieldType[@name='TextField']@class='org.apache.solr.schema.TextField';

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    SET fields.field[@name='comment']@type='TextField';

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Drop a field and a field type

The first command drops the field from the search index and the second command drops the field type:

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    DROP field comment;

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    DROP types.fieldType[@name='TextField'];

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

Add a field type and a dynamic field

The first command adds the TextField type, which must exist before the dynamic field is added by the second command:

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    ADD types.fieldType[@class='org.apache.solr.schema.TextField', @name='TextField']
    WITH '{"analyzer":{"class":"org.apache.lucene.analysis.standard.StandardAnalyzer"}}';

  ALTER SEARCH INDEX SCHEMA ON cycling.comments
    ADD dynamicField[@name='*fieldname', @type='TextField'];

Ensure your dynamic field name has a leading or a trailing asterisk character.

To apply the schema changes and rebuild the index:

  REBUILD SEARCH INDEX ON cycling.comments;

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