DSE Search Indexing Quick Start
This quickstart example provides an overview of creating and altering DSE Search indexes using CQL index management commands.
Creating a search index
-
Launch cqlsh and create a tutorial keyspace on an DSE Search node:
cqlsh
-
Set up the table schema and create a default index:
-
Create the keyspace, create the table, and then create the search index on the users table from the KillrVideo application:
CREATE KEYSPACE demo WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 1}; 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 SCHEMA View the pending search index schema
The generated schema looks like this:
<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 fieldType to the schema with this ALTER SEARCH INDEX SCHEMA statement:
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" } ] } ] }$$;
The dollar signs ($$) syntax in the ALTER SEARCH INDEX SCHEMA example are dollar quotes to escape a single quotation mark, see Escaping single quotation marks. This new fieldType has 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 firstname and lastname fields:
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';
-
In contrast to the dsetool search index management commands, all changes made with ALTER SEARCH INDEX affect only the pending resources for the search index. To use the 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;
-