DSE Search index quickstart
This quickstart provides an overview of creating and altering DSE Search indexes using CQL index management commands.
-
Connect CQL shell (
cqlsh) to a DSE Search node, and then create atutorialkeyspace:CREATE KEYSPACE demo WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 1}; -
Create a table and search index:
CREATE TABLE demo.users ( userid uuid, firstname text, lastname text, email text, created_date timestamp, PRIMARY KEY (userid)); CREATE SEARCH INDEX ON demo.users;A new search index is generated on the table. Existing data is reindexed.
-
Use the CQL shell
DESCRIBE SEARCH INDEX SCHEMAcommand to view the pending search index schema:<schema name="autoSolrSchema" version="1.5"> <types> <fieldType class="org.apache.solr.schema.TextField" name="TextField"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> <fieldType class="org.apache.solr.schema.UUIDField" name="UUIDField"/> <fieldType class="org.apache.solr.schema.TrieDateField" name="TrieDateField"/> </types> <fields> <field indexed="true" multiValued="false" name="firstname" stored="true" type="TextField"/> <field docValues="true" indexed="true" multiValued="false" name="userid" stored="true" type="UUIDField"/> <field indexed="true" multiValued="false" name="email" stored="true" type="TextField"/> <field indexed="true" multiValued="false" name="lastname" stored="true" type="TextField"/> <field docValues="true" indexed="true" multiValued="false" name="created_date" stored="true" type="TrieDateField"/> </fields> <uniqueKey>userid</uniqueKey> </schema> -
To increase tolerance of non-ASCII characters in the name field, add a new
fieldTypeto the schema with the followingALTER SEARCH INDEX SCHEMAstatement.Double dollar signs (
$$) are dollar quotes that are used to escape a single quotation mark.ALTER SEARCH INDEX SCHEMA ON demo.users ADD types.fieldType [ @name='TextField_intl' , @class='org.apache.solr.schema.TextField' ] WITH $${ "analyzer": [ { "type": "index", "tokenizer": { "class": "solr.StandardTokenizerFactory" }, "filter": [ { "class": "solr.LowerCaseFilterFactory" }, { "class": "solr.ASCIIFoldingFilterFactory" } ] }, { "type": "search", "tokenizer": { "class": "solr.StandardTokenizerFactory" }, "filter": [ { "class": "solr.LowerCaseFilterFactory" }, { "class": "solr.ASCIIFoldingFilterFactory" } ] } ] }$$; -
Run
DESCRIBE SEARCH INDEX SCHEMAagain to view the updated schema.The new
fieldTypehas separate index and search analysis phases:<fieldType class="org.apache.solr.schema.TextField" name="TextField_intl"> <analyzer type="index"> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.ASCIIFoldingFilterFactory"/> <tokenizer class="solr.StandardTokenizerFactory"/> </analyzer> <analyzer type="search"> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.ASCIIFoldingFilterFactory"/> <tokenizer class="solr.StandardTokenizerFactory"/> </analyzer> </fieldType> -
Change the type on the
firstnameandlastnamefields:ALTER SEARCH INDEX SCHEMA ON demo.users SET field[@name='firstname']@type = 'TextField_intl';ALTER SEARCH INDEX SCHEMA ON demo.users SET field[@name='lastname']@type = 'TextField_intl';All changes made with ALTER SEARCH INDEX affect only the pending resources for the search index.
-
To apply the pending changes, reload the index:
RELOAD SEARCH INDEX ON demo.users;If there is existing data in the index, rebuild the index:
REBUILD SEARCH INDEX ON demo.users;