1

When I used MySQL I was able to query the database with a statement like SELECT * FROM table WHERE col LIKE "%attribute%";

Is there a way I can do that in Cassandra?

Ravaal
  • 3,233
  • 6
  • 39
  • 66

3 Answers3

3

Cassandra CQL doesn't have a LIKE operator. It has limited filtering capabilities so you are restricted to equals, range queries on some numeric fields, and the IN operator which is similar to equals.

The most common approach to doing searches of Cassandra data seems to be pairing Cassandra with Apache Solr. Or you can pair it with Apache Spark which has more filtering capabilities than CQL.

Jim Meyer
  • 9,275
  • 1
  • 24
  • 49
  • 1
    You may also find these posts interesting: http://stackoverflow.com/questions/13023424/phonetic-filter-factory-for-hindi & http://stackoverflow.com/questions/22552446/solr-search-using-contains-sound-like – Caleb Rackliffe Sep 11 '15 at 18:44
  • 1
    check out DSE Search http://docs.datastax.com/en/datastax_enterprise/4.7/datastax_enterprise/srch/srchIntro.html – phact Sep 11 '15 at 19:26
1

If your col is a collection of data like set, list, map. You could use CONTAINS, to perform search.

Sample:

SELECT id, description FROM products WHERE features CONTAINS '32-inch';

For map data type,

SELECT id, description FROM products WHERE features CONTAINS KEY 'refresh-rate';

References: http://www.datastax.com/dev/blog/cql-in-2-1

Swam Guru
  • 473
  • 5
  • 9
  • (lastname | firstname -----------+----------- Doe | John Farther | Jacob Huey | Roger Anzaldo | Daniel Penrose | Guyman Sigman | Matt McCarthy | Bob) --this is my table. How do I select * from the table where the first name contains "man". It's coming back with an operator error. QUERY: cqlsh:demo> select firstname, lastname from demo where firstname contains 'man'; InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: " – Ravaal Sep 13 '15 at 20:33
  • Just 2 questions, to help you better, 1) Is "firstname" column a collection of data like Set, List or Map? Example: firstname = {name1, name2, name3} 2) If your firstname is a collection, Then Did you define "firstname" as Secondary or primary index? – Swam Guru Sep 15 '15 at 07:29
  • lastname is primary key, firstname is just text. – Ravaal Sep 15 '15 at 15:22
  • contains can only be used for collection data type, which holds list of data – Swam Guru Sep 19 '15 at 17:12
  • Thank you for clearing that up. I was wondering why it wasn't working. – Ravaal Sep 21 '15 at 12:50
0

CQL LIKE statements now available are in Scylla Open Source 3.2 RC1, the release candidate for Scylla, a CQL-compatible database. We'd love feedback before release. Here's the details:

  • CQL: LIKE Operation #4477

The new CQL LIKE keyword allows matching any column to a search pattern, using % as a wildcard. Note that LIKE only works with ALLOW FILTERING.

LIKE Syntax support:

'_' matches any single character

'%' matches any substring (including an empty string)

'\' escapes the next pattern character, so it matches verbatim

any other pattern character matches itself

an empty pattern matches empty text fields

For example:

INSERT INTO t (id, name) VALUES (17, ‘Mircevski’)

SELECT * FROM t where name LIKE 'Mirc%' allow filtering

Source: [RELEASE] Scylla 3.2 RC1 2

Peter Corless
  • 781
  • 3
  • 12