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_list 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-list.cql[tag=insert_allan]

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

  1. Create an index that excludes the blist_ map column:

    include:cycling-examples:example$table-birthday-list.cql[tag=index]
  2. View the active schema:

    include:cycling-examples:example$table-birthday-list.cql[tag=desc_active]

    DSE sets CQL text to Solr StrField 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.

  3. Define the blist_age type and configure a field definition:

    include:cycling-examples:example$table-birthday-list.cql[tag=type]
  4. Define the blist_nation field as a string type, which has a corresponding type definition of @type='StrField':

    include:cycling-examples:example$table-birthday-list.cql[tag=alter]
  5. View the pending changes to the schema to ensure that the syntax is correct:

    include:cycling-examples:example$table-birthday-list.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>
  6. Reload the index configuration and schema to push the changes live:

    include:cycling-examples:example$table-birthday-list.cql[tag=reload]
  7. Rebuild the index whenever fields are added:

    include:cycling-examples:example$table-birthday-list.cql[tag=rebuild]
  8. Use the map fields to filter queries:

    • Limit by age 23:

      include:cycling-examples:example$birthday_list-table_queries.cql[tag=select_23]
      include:cycling-examples:example$select_23_from_birthday_list.results[]
    • Limit by nation GERMANY, which is case-sensitive because the type is a string:

      include:cycling-examples:example$birthday_list-table_queries.cql[tag=select_germany]
      include:cycling-examples:example$select_germany_from_birthday_list.results[]

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com