在cassandra的主键上匹配'like'的模式

问题描述 投票:1回答:2

在Cassandra中,'like'可用于查找满足SASI索引列上搜索模式的匹配结果,它运行得非常好,但如何在主键上使用。

这是我的表:

CREATE TABLE indexxx (
    title VARCHAR,
    PRIMARY KEY (title));

主键上不允许索引,

CREATE CUSTOM INDEX testtt ON indexxx (title) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'mode': 'CONTAINS', 'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer', 'case_sensitive': 'false'};



InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot create secondary index on partition key column title"

当试图使用没有sasi索引时,

select * from indexxx  where title like '%kkk%' ;

InvalidRequest: Error from server: code=2200 [Invalid query] message="LIKE restriction is only supported on properly indexed columns. title LIKE '%kkk%' is not valid." 
cassandra nosql cql cql3 cassandra-3.0
2个回答
2
投票

在主键的分区列上不可能使用LIKE子句。这是因为分区值始终是哈希值,并且在搜索时仅使用相应的标记。

但是,您可以借助SASI索引在聚类列或任何其他非集合列(未设置,映射或列表)上使用LIKE子句。


0
投票

您可以创建另一个列,该列将包含与title title_sasi相同的值,并在此新列上应用索引。

表结构将是

CREATE TABLE indexxx (
    title VARCHAR,
    title_sasi VARCHAR,
    PRIMARY KEY (title));

指数:

CREATE CUSTOM INDEX testtt ON indexxx (title_sasi) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'mode': 'CONTAINS', 'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer', 'case_sensitive': 'false'};
© www.soinside.com 2019 - 2024. All rights reserved.