ALTER SEARCH INDEX 

Changes a search index for DSE Search.

Alters a search index schema or configuration for DSE Search. After you modify the search schema or config with this command, you must use the RELOAD SEARCH INDEX command to recognize the changes.

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.

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)
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' 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 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

Alter the search index to alter the search index schema or config, where:
json
A literal string that contains a JSON object representation of the schema or config element.
element_path
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
The field of the element in the schema or solrConfig resource files.

Shortcuts 

Shortcuts for common elements are supported when altering configuration and schema elements.

Shortcuts for config element paths
Shortcut Verb Type Comment
autoCommitTime SET int 10000
defaultQueryField SET, DROP string Not configured when resources are auto generated.
directoryFactory SET string Specify exclusive of directoryFactoryClass.

StandardDirectoryFactory

EncryptedFSDirectoryFactory

filterCacheLowWaterMark SET int Default is 128 when resources are auto generated.
filterCacheHighWaterMark SET int Default is 256 when resources are auto generated.
mergeFactor SET int Default is 10 when resources are auto generated.
mergeMaxThreadCount SET int Must configure with mergeMaxMergeCount. Not configured when resources are auto generated.
mergeMaxMergeCount SET int Must configure with mergeMaxThreadCount. Not configured when resources are auto generated.
ramBufferSize SET int Default is 512 when resources are auto generated.
realtime SET boolean Default is false when resources are auto generated.
The field shortcut allows adding or dropping a field from the schema:
ALTER SEARCH INDEX SCHEMA ON solr.wiki ADD fields.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.
Note: Adding the leading element fields. in ADD fields.field field_name is optional and provides only cosmetic structure.

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 fields.field mapfield;
Note: Adding the leading element fields. in ADD fields.field mapfield is optional and provides only cosmetic structure.
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 basefieldname;
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 fields.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" />
Note: Adding the leading element fields. in ADD fields.field fieldname is optional and provides only cosmetic structure.
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 ;

Add a type with its attributes

For example, to add a SpatialRecursivePrefixTreeFieldType that uses the Java Topology Suite (JTS) to enable performing spatial queries that include polygon shapes. Spatial queries with polygons require the JTS JAR.
ALTER SEARCH INDEX SCHEMA ON ks.tb ADD types.fieldType[@name='location_rpt', @class='solr.SpatialRecursivePrefixTreeFieldType', 
          @spatialContextFactory='com.spatial4j.core.context.jts.JtsSpatialContextFactory', 
          @distErrPct='0.025', @maxDistErr='0.0000009',@units='degrees'];
which adds the location_rpt field type to the schema:
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
          spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
          distErrPct="0.025"
          maxDistErr="0.000009"
          units="degrees"
          />
        
Add a configuration request handler:
ALTER SEARCH INDEX CONFIG ON ks.tb 
          ADD requestHandler[@name='/elevate',@class='solr.SearchHandler',@startup='lazy'] 
          WITH  $${'defaults':[{'echoParams':'explicit'}],'last-components':['elevator’]}$$
which adds the requestHandler element to the config:
<requestHandler name="/elevate" class="solr.SearchHandler">
          <lst name="defaults">
          <str name="echoParams">explicit</int>
          </lst>
          <arr name="last-components">
          <str>elevator</str>
          </arr>
          </requestHandler>