Cassandra使用复合索引和二次合并

use*_*899 6 cql cassandra nosql

我们想使用cassandra来存储复杂数据,
但我们无法弄清楚如何组织索引.

我们的表(列族)看起来像这样:

Users =
  { 
    RandomId int,
    Firstname varchar,
    Lastname varchar,
    Age int,
    Country int,
    ChildCount int
  }
Run Code Online (Sandbox Code Playgroud)

我们有必填字段(名字,姓氏,年龄)和额外搜索选项(Country,ChildCount)的查询.
我们应该如何组织索引以更快地进行此类查询?

首先我想,在(名字,姓氏,年龄)上创建综合索引并在剩余字段(Country和ChildCount)上添加单独的二级索引是很自然的.
但是在创建二级索引后我无法在表中插入行,我无法查询该表.

运用

  • cassandra 1.1.0
  • 带有--cql3选项的cqlsh.

我们欢迎任何其他建议来解决我们的问题(带有强制性和附加选项的复杂查询).

ces*_*are 2

这是我的想法。您可以简单地创建一个列族,将 RandomId 作为行键,将所有剩余字段简单地作为列(例如,列名“firstname”,列值“jonh”)。之后,您必须为每个列创建一个二级索引。您的值的基数似乎很低,因此它应该稍微有效。

CQL 代码应该类似于:

create column family users with comparator=UTF8Type and column_metadata=[{column_name:  firstname, validation_class: UTF8Type,index_type: KEYS},
{column_name: lastname, validation_class: UTF8Type, index_type: KEYS},
{column_name: contry, validation_class: IntegerType, index_type: KEYS},
{column_name: age, validation_class: IntegerType, index_type: KEYS]},
{column_name: ChildCount, validation_class: IntegerType, index_type: KEYS]];
Run Code Online (Sandbox Code Playgroud)

一个很好的参考可能是http://www.datastax.com/docs/0.7/data_model/secondary_indexes

如果我错了请告诉我;