Indexing map columns
DataStax Enterprise (DSE) Search indexes a CQL map column using a Solr dynamic field. Dynamic fields apply the field definition using a wildcard match on the name. In the search index schema, DSE sets the dynamic field name to the CQL column name with an asterisk appended. DSE parses the data from a map using the key name and Solr will index only the keys that have the column name as the prefix. Keys that do not have the column name as a prefix are ignored.
For example, when creating a search index with the default settings on the cycling birthday table, the blist_
map column definition is:
<dynamicField indexed="true" multiValued="false" name="blist_*" type="StrField"/>
When DSE builds the index from the CQL rows, the key name is used (not the column name).
Therefore, all keys that have the blist_
as the prefix in the example are indexed and the rest are ignored.
Only blist_age
and blist_nation
are indexed when the following data is inserted:
include:cycling-examples:example$table-birthday.cql[tag=data-insert-one]
All key-value pairs in CQL maps have the same data type.
The map in the example above sets all values to text (blist map<text,text>
).
Because DSE Search loads the data by mapping the key name to the Solr dynamic field name, you can customize field type for each key.
Prerequisites
This section walks you through the process of customizing the search index for data that has the same three map keys in every record, blist_age, bday (birth date), and blist_nation where only blist_age and blist_nation are indexed.
Set up the following keyspace and table to use this example:
Procedure
-
Create an index that excludes the
blist_
map column:include:cycling-examples:example$table-birthday.cql[tag=index]
-
View the active schema:
include:cycling-examples:example$table-birthday.cql[tag=desc_active]
DSE sets CQL
text
to SolrStrField
type.<?xml version="1.0" encoding="UTF-8" standalone="no"?> <schema name="autoSolrSchema" version="1.5"> <types> <fieldType class="org.apache.solr.schema.StrField" name="StrField"/> </types> <fields> <field indexed="true" multiValued="false" name="cyclist_name" type="StrField"/> </fields> <uniqueKey>cyclist_name</uniqueKey> </schema>
To set
blist_age
to an integer, the type definition is also required. -
Define the
blist_age
type and configure a field definition:include:cycling-examples:example$table-birthday.cql[tag=type]
-
Define the
blist_nation
field as a string type, which has a corresponding type definition of@type='StrField'
:include:cycling-examples:example$table-birthday.cql[tag=alter]
-
View the pending changes to the schema to ensure that the syntax is correct:
include:cycling-examples:example$table-birthday.cql[tag=desc_pending]
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <schema name="autoSolrSchema" version="1.5"> <types> <fieldType class="org.apache.solr.schema.StrField" name="StrField"/> <fieldType class="org.apache.solr.schema.TrieIntField" name="TrieIntField"/> </types> <fields> <field indexed="true" multiValued="false" name="cyclist_name" type="StrField"/> <field indexed="true" multiValued="false" name="blist_age" type="TrieIntField"/> <field indexed="true" multiValued="false" name="blist_nation" type="StrField"/> </fields> <uniqueKey>cyclist_name</uniqueKey> </schema>
-
Reload the index configuration and schema to push the changes live:
include:cycling-examples:example$table-birthday.cql[tag=reload]
-
Rebuild the index whenever fields are added:
include:cycling-examples:example$table-birthday.cql[tag=rebuild]
-
Use the map fields to filter queries:
-
Limit by age 23:
include:cycling-examples:example$table-birthday_queries.cql[tag=select_23]
include:cycling-examples:example$select_23_from_birthday.results[]
-
Limit by nation GERMANY, which is case-sensitive because the type is a string:
include:cycling-examples:example$table-birthday_queries.cql[tag=select_germany]
include:cycling-examples:example$select_germany_from_birthday.results[]
-