Secondary index

Jun 5, 2012 at 3:32 PM

Hi,
can you help me please with creating secondary index on column? I have looked for solution in documentation and I havent found it.

Thanks

Oddysse

Developer
Jun 5, 2012 at 4:41 PM

It's probably easier to use cassandra-cli or cqlsh. To do it from code, here's a sample:

    var ksDef = ctx.DescribeKeySpace();
    var cfDef = ksDef.Cf_defs
        .First(c => c.Name == this._ColumnFamily);
    var columnDef = cfDef.Column_metadata
        .FirstOrDefault(c => SequenceComparer<byte>.Default.Equals(c.Name, this._ColumnName));
    if (columnDef == null)
    {
        columnDef = new ColumnDef
        {
            Name = this._ColumnName,
            Validation_class = "UTF8Type",
            Index_type = IndexType.KEYS,
        };
        cfDef.Column_metadata.Add(columnDef);
    }
    else if (columnDef.Index_type == IndexType.KEYS)
        return;
    else
        columnDef.Index_type = IndexType.KEYS;
    ctx.SystemUpdateColumnFamily(cfDef);

Jun 19, 2012 at 6:57 PM

Thank you for help