go - cassandra中复合键的二级索引

标签 go cassandra

我在 cassandra 中有这张表

CREATE TABLE global_product_highlights (
  deal_id text,
  product_id text,
  highlight_strength double,
  category_id text,
  creation_date timestamp,
  rank int,
  PRIMARY KEY (deal_id, product_id, highlight_strength)
)

当我在 Golang 中触发以下查询时

err = session.Query("select product_id from global_product_highlights where category_id=? order by highlight_strength DESC",default_category).Scan(&prodId_array)

我收到错误:不支持使用第二个索引的 ORDER BY。

我有一个关于 category_id 的索引。

我不完全明白二级索引是如何应用于cassandra中的组合键的。

如果有人能解释和纠正这个问题,我们将不胜感激。

最佳答案

Cassandra 中的 ORDER BY 子句仅适用于您的第一个聚类列(主键中的第二列),在本例中为您的 product_id。 This DataStax doc指出:

Querying compound primary keys and sorting results ORDER BY clauses can select a single column only. That column has to be the second column in a compound PRIMARY KEY.

因此,如果您想让表格按 highlight_strength 排序,则需要将该字段设置为第一个聚类列。

关于go - cassandra中复合键的二级索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22361583/

相关文章:

testing - 针对 xml/字符串测试失败的自定义 testify 输出

docker - 无法使用 Docker SDK 中的端口范围语法进行端口转发

go - 在选择中使用子查询

cassandra - Cassandra NoHost可用: error in CQLSH

Cassandra Vnodes和 token 范围

hadoop - Datastax Enterprise 3.2 配置单元超时异常

swift - Swift 和 Go 之间的 Zlib 压缩

go - 如何在 Golang 中使用动态键解析 YAML

cassandra - cql/cassandra 中是否有 "alter table add column if column not exists"的等效查询?

java - 使用 IN 子句过滤 Spark Cassandra 连接器