Chaity
Chaity

Reputation: 1388

How is it possible to do wildcard search on apache cassandra at the beginning of the string like '%string' as we do in Sql?

i need to do wildcard search like this on apache cassandra, SELECT * FROM table_name where col_name like "string%";

I know there is no wildcard support like this in Cassandra. I have to maintain some indices for this purpose. I have read through these links which were very much helpful.
Cassandra CQL 3 - Prefix Select
is there any trick to do wildcards search on apache cassandra?

I could design data model which allows wild cards at the end of the string and where I can get result like -->
SELECT * FROM table_name where col_name like 'str%'; by maintaning an index and with normal range queries from str:sts. But I want wild cards at the beginning of the string like '%str'.
Is there any possible way to do this? Any help will be appreciated.

Thanks in advance.

Upvotes: 1

Views: 3390

Answers (1)

Roman Tumaykin
Roman Tumaykin

Reputation: 1931

Cassandra is not a right tool to do any searches beyond the primary keys. You should better look for something like Solr for this type of job.

Of course you can create a table with all triplet combinations of letters and numbers as a partition key, and then reference to the partitioning or primary keys of the table which contains the data.

For example you will have rows with the partition key "aaa", "aab", "aac", ..., "ZZZ", etc, and the rest of the columns will tell you the values of the primary key of the table_name where this triplet exists in the col_name. Then you will have to update this table every time you modify the data in that col_name of the table_name.

But I don't think it will be a very efficient use of Cassandra.

Upvotes: 1

Related Questions