Cassandra 2 - list existing indexes with CQL 3

Maciej Miklas picture Maciej Miklas · Jan 13, 2014 · Viewed 14.6k times · Source

Is there a CQL query to list all existing indexes for particular key space, or column family?

Answer

jorgebg picture jorgebg · Jan 14, 2014

You can retrieve primary keys and secondary indexes using the system keyspace:

SELECT column_name, index_name, index_options, index_type, component_index 
FROM system.schema_columns 
WHERE keyspace_name='samplekp'AND columnfamily_name='sampletable';

Taking, for example, the following table declaration:

CREATE TABLE sampletable (
key text,
date timestamp,
value1 text,
value2 text,
PRIMARY KEY(key, date));

CREATE INDEX ix_sample_value2 ON sampletable (value2);

The query mentioned above would get something this results:

 column_name | index_name       | index_options | index_type | component_index
-------------+------------------+---------------+------------+-----------------
        date |             null |          null |       null |               0
         key |             null |          null |       null |            null
      value1 |             null |          null |       null |               1
      value2 | ix_sample_value2 |            {} | COMPOSITES |               1