我在 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/