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 |
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
Syntax conventions | Description |
---|---|
UPPERCASE |
Literal keyword. |
Lowercase |
Not literal. |
|
Variable value. Replace with a user-defined value. |
|
Optional.
Square brackets ( |
|
Group.
Parentheses ( |
|
Or.
A vertical bar ( |
|
Repeatable.
An ellipsis ( |
|
Single quotation ( |
|
Map collection.
Braces ( |
Set, list, map, or tuple.
Angle brackets ( |
|
|
End CQL statement.
A semicolon ( |
|
Separate the command line options from the command arguments with two hyphens ( |
|
Search CQL only: Single quotation marks ( |
|
Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files. |
- 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:
-
field
-name
attribute -
fieldType
-name
attribute -
dynamicField
-name
attribute -
copyField
-source
anddest
See Managing search index fields and Dropping columns from the index in the documentation.
-
- 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:
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 |
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;