Search code examples
cassandracql

Cassandra 2 - list existing indexes with CQL 3


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


Solution

  • 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