CQL for Cassandra 2.x

Indexing a column

You can use cqlsh to create an index on column values. In Cassandra 2.1 and later, you can index collection columns. Indexing can impact performance greatly. Before creating an index, be aware of when and when not to create an index.


  1. Creates an index on the state and birth_year columns in the users table.
    cqlsh:demodb> CREATE INDEX state_key ON users (state);
    cqlsh:demodb> CREATE INDEX birth_year_key ON users (birth_year);
  2. Query the columns that are now indexed.
    cqlsh:demodb> SELECT * FROM users
                    WHERE gender = 'f' AND
                    state = 'TX' AND
                    birth_year > 1968
                    ALLOW FILTERING;