Indexing a collection 

You can index collections and query the database to find a collection containing a particular value.

In Apache Cassandra™ 2.1 and later, you can index collections and query the database to find a collection containing a particular value. Continuing with the music service example, suppose you want to find songs tagged blues and that debuted at the Fillmore. Index the tags set and venue map. Query for values in the tags set and the venue map, as shown in the next section.

CREATE INDEX ON playlists (tags);
CREATE INDEX mymapvalues ON playlists (venue);

Specifying a name for the index, such as mymapindex, is optional.

Indexing collection map keys 

The last example created the index on the venue collection values by using the venue map column name to create the index. You can also create an index on map collection keys. A map key is the literal to the left of the colon in the JSON-style array. A map value is the literal to the right of the colon.

{ literal : literal, literal : literal ... }

For example, the collection keys in the venue map are the timestamps. The collection values in the venue map are 'The Fillmore' and 'Apple Barrel'.

Indexes on the keys and values of a map cannot co-exist. For example, if you created mymapindex, you would need to drop it to create an index on the map keys using the KEYS keyword and map name in nested parentheses:

DROP INDEX mymapvalues;
CREATE INDEX mymapkeys ON playlists (KEYS(venue));