Cassandra范围使用允许过滤搜索二级索引 [英] Cassandra Range Search on Secondary Index with Allow Filtering

查看:695
本文介绍了Cassandra范围使用允许过滤搜索二级索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩Cassandra 3.我在一个整数列上添加了一个辅助索引,然后我想做一个范围查询。首先它抛出一个错误:

I'm playing with Cassandra 3. I added a secondary index on a column of integer, then I want to do a range query. First it threw an error:

InvalidRequest: code=2200 [Invalid query] message="No supported secondary index found for the non primary key columns restrictions"

所以我添加了允许过滤

cqlsh:mykeyspace> SELECT * FROM test ;

id | id2 | age | extra
----+-----+-----+-------
  1 |   1 |   1 |     1
  2 |   2 |   2 |     2

(2 rows)
cqlsh:mykeyspace > CREATE INDEX test_age on test (extra) ;
cqlsh:mykeyspace > select * FROM test WHERE extra < 2 ALLOW FILTERING ;

 id | id2  | age | extra
----+------+-----+-------
  1 |    1 |   1 |     1
  2 | null |   2 |  null

(2 rows)

为什么会发生?

推荐答案

对于Cassandra 3.0+,你需要调查物化视图 - 他们

With Cassandra 3.0+, you'll want to investigate Materialized Views - they're designed to be a more functional version of secondary indexes, working around most of the traditional downfalls.

您几乎不想在高解读度中使用传统的二级索引环境,并且ALLOW FILTERING通常很糟糕。

You almost never want to use traditional secondary indexes in high-read production environments, and ALLOW FILTERING is generally awful.

这篇关于Cassandra范围使用允许过滤搜索二级索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆