ALTER SEARCH INDEX 

Alters a search index for DSE Search.

Alters a search index for DSE Search.

Synopsis 

ALTER SEARCH INDEX ( SCHEMA | CONFIG )
ON [keyspace_name.]table_name
   (ADD element_path WITH json
    | ADD field field_name  
    | SET element_path(@attribute = value) 
    | DROP element_path(@attribute
    | DROP field field_name)
where:
  • json is a literal string that contains a JSON object representation of the schema or config element.
  • element_path is a specified element in the schema or solrConfig XML resource files. Each element in the path can have a comma separated set of associated attributes. Common options have shortcuts for config and schema elements.
  • @attribute is the field of the element in the schema or solrConfig resource files.
Legend
Syntax conventions Description
UPPERCASE Literal keyword.
Lowercase Not literal.
Italics 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.
<datatype1,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.

EBNF 

EBNF syntax:
alterSearchIndex ::= 'ALTER' 'SEARCH' 'INDEX' ('SCHEMA' | 'CONFIG')
                     'ON' columnFamilyName
                     (
                        ('ADD' elementPath 'WITH' json) |
                        ('ADD' 'field' fieldname) |
                        ('SET' elementPath('@' attribute)? '=' value) |
                        ('DROP' elementPath('@' attribute)?) |
                        ('DROP' 'field' fieldname)
                     )
elementPath ::= elementName ('[' '@' attributeName '=' attributeValue (',' '@' attributeName '=' attributeValue)* ']')?
                ( '.' elementName ('[' '@' attributeName '=' attributeValue (',' '@' attributeName '=' attributeValue)* ']')?)*
Railroad diagram:
alterSearchIndex


Image shows a railroad diagram for the ALTER SEARCH INDEX search CQL command

columnFamilyName
Image shows a railroad diagram of columnFamilyName

elementPath
Image shows a railroad diagram of elementPath

Alter the search index to alter the search index schema or config.
Note: New fields that are added with the ALTER SEARCH INDEX SCHEMA command do not observe the profile values that were specified at the index create time. For example, if the index was created with the spaceSavingNoTextfield resource generation profile, that profile is not observed for new fields that are added.

Shortcuts for config and schema elements 

Shortcuts for common elements are supported for config and schema elements.

Shortcuts for config element paths
Shortcut Verb Type Comment
autoCommitTime SET int updateHandler.autoSoftCommit.maxTime
defaultQueryField SET, DROP string standard - StandardDirectoryFactory

encrypted - EncryptedFSDirectoryFactory

directoryFactory SET string  
filterCacheLowWaterMark SET int  
filterCacheHighWaterMark SET int  
mergeFactor SET int  
mergeMaxThreadCount SET int  
mergeMaxMergeCount SET int  
ramBufferSize SET int  
realtime SET boolean  
The field shortcut allows adding or dropping a field from the schema:
ALTER SEARCH INDEX SCHEMA ON solr.wiki ADD field field_name;
ALTER SEARCH INDEX SCHEMA ON solr.wiki DROP field field_name;
where field_name is the unquoted name of the column to add to or drop from the search schema.

Dynamic fields 

Map columns are added as dynamic fields:
ALTER TABLE solr.wiki ADD mapfield map<text, int>;
ALTER SEARCH INDEX SCHEMA ON solr.wiki ADD field mapfield;
Creates the following search schema field:
<dynamicField indexed="true" multiValued="false" name="mapfield*" stored="true" type="TrieIntField" />
A dynamic field can be dropped using the base field name:
ALTER SEARCH INDEX SCHEMA ON solr.wiki DROP field fieldname;
Or drop the dynamic field using the quoted full dynamic name:
ALTER SEARCH INDEX SCHEMA ON solr.wiki DROP field "fieldname*";

Tuples 

Tuple columns are added as multiple fields:
ALTER TABLE solr.wiki ADD fieldname tuple<text,int>;
ALTER SEARCH INDEX SCHEMA ON solr.wiki ADD field fieldname;
Adds the following to the schema:
<field indexed="true" multiValued="false" name="fieldname" stored="true" type="TupleField" />
<field indexed="true" multiValued="false" name="fieldname.field1" stored="true" type="TextField" />
<field indexed="true" multiValued="false" name="fieldname.field2" stored="true" type="TrieIntField" />
When dropping the base field name:
ALTER SEARCH INDEX SCHEMA ON solr.wiki DROP field fieldname;

Drops the TupleField and all the child fields.

To drop individual child fields:
ALTER SEARCH INDEX SCHEMA ON solr.wiki DROP field "fieldname.field1";

Field types 

Field types are inferred when fields are added. The field types are added if they do not exist in the schema. Field type names are generated using the field type name as the simple name of the field type. For example, in a table that has no int fields:
ALTER TABLE ks.tb ADD intfield int;
ALTER SEARCH INDEX SCHEMA ON ks.tb ADD field intfield;
Adds the following field:
<field indexed="true" multiValued="false" name="intfield" stored="true" type="TrieIntField" />

And the following field type:

<fieldType name="TrieIntField" class="org.apache.solr.schema.TrieIntField"/>

Examples

The search index is altered for the wiki.solr keyspace and table, and the specified options.

Adds schema fields fieldname and TextField:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD field[@name='fieldname', @type='TextField'];
Add schema field with shortcut:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD field fieldname;
Changes schema fieldname to anotherFieldName:
ALTER SEARCH INDEX SCHEMA ON wiki.solr SET field[@name='fieldname']@name = 'anotherFieldName';
Changes schema fieldname field type to StrField:
ALTER SEARCH INDEX SCHEMA ON wiki.solr SET field[@name='fieldname']@type = 'StrField';
Adds schema with a copied field:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='sourcefield',@dest='destfield'];
Drops schema field fieldname:
ALTER SEARCH INDEX SCHEMA ON wiki.solr DROP field[@name='fieldname'];
Drops schema field with shortcut:
ALTER SEARCH INDEX SCHEMA ON wiki.solr DROP field fieldname;
Adds schema with a copied field:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='sourcefield',@dest='destfield'];
Sets schema with a copied field:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='sourcefield',@dest='destfield'];
Adds schema with a copied field:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='sourcefield',@dest='destfield'];
Sets index configuration with shortcut for automatic soft commit max time to 10000ms:
ALTER SEARCH INDEX CONFIG ON wiki.solr SET autoCommitTime = 10000;
Configure live indexing and reload the altered index:
ALTER SEARCH INDEX CONFIG ON wiki.solr SET autoCommitTime = 100;
ALTER SEARCH INDEX CONFIG ON wiki.solr SET realtime = true;
ALTER SEARCH INDEX CONFIG ON wiki.solr SET ramBufferSize = 2048;
RELOAD SEARCH INDEX ON wiki.solr ;