Cassandra中的正则表达式搜索或LIKE类型功能 [英] Regular expression search or LIKE type feature in cassandra

查看:324
本文介绍了Cassandra中的正则表达式搜索或LIKE类型功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用datastax cassandra ver 2.0。
我们如何使用正则表达式在cassandra列中搜索值?是否有实现 LIKE(如sQL)功能的方法?

I am using datastax cassandra ver 2.0. How do we search in cassandra column a value using regular expression.Is there way to achieve 'LIKE' ( as in sQL) functionality ?

CREATE TABLE Mapping (
id timeuuid,
userid text,
createdDate timestamp,
createdBy text,
lastUpdateDate timestamp,
lastUpdateBy text,
PRIMARY KEY (id,userid)
);

我插入了以下测试记录。

I inserted few test records as below.

       id                                  | userid   | createdby
     -------------------------------------+----------+-----------
      30c78710-c00c-11e3-bb06-1553ee5e40dd |      Jon |     admin
      3e673aa0-c00c-11e3-bb06-1553ee5e40dd |     Jony |     admin
      441c4210-c00c-11e3-bb06-1553ee5e40dd | Jonathan |     admin

我需要搜索记录,其中userid包含单词 jon。因此,在结果中,我得到了所有记录,包含jon,jony,jonathan。

I need to search records, where userid contains the word 'jon'.So that in results, i get all records, containing jon,jony,jonathan.

我知道,cassandra中没有sql LIKE功能。
但是有什么方法可以在cassandra中实现它吗?
(注意:我正在使用datastax-java驱动程序作为客户端api)。

I know,there is no sql LIKE functionality in cassandra. But is there any way to achieve it in cassandra ? (NOTE: I am using datastax-java driver as client api).

推荐答案

您使用DSE还是社区版本?对于DSE,请考虑为这些类型的查询提供一个Solr节点。如果不是这样,则可以使用lucene / solr之类的东西作为Cassandra之外的特定功能的反向索引。如果只设置了cassandra,这可能会很麻烦,在这种情况下,请按照Ananth的建议设置一个手动倒排索引。一种选择是保留2-3个字符的前缀行,以保留分区索引。您可以查询这些内容,在客户端找到合适的分区,然后对目标数据进行另一个查询。

Are you using DSE or the community version? In case of DSE, consider having a Solr node for these types of queries. If not, maybe use something like lucene / solr as an inverted index outside of cassandra for that particular functionality. That may be a hassle if all you have is cassandra set up, in which case, have a manual inverted index as Ananth suggested. One option is to keep rows of 2-3 character prefixes that hold indices to partitions. You could query those, find the appropriate partitions client side and then issue another query against the target data.

这篇关于Cassandra中的正则表达式搜索或LIKE类型功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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