Wait! Back away from the Cassandra secondary index. It’s ok for some use cases, but it’s not an easy button. “But I need to search through a bunch of columns to look for the data… and I can’t model that in C*, even after watching all of Patrick McFadins data modeling videos. What do I do?” The answer, dear developer, is in DSE Search. With it’s easy Solr API, Lucene indexes (and fault tolerance) you can search data stored in your Cassandra database until your heart’s content. Take my hand. I will show you how.
15. Confidential 15
SELECT * FROM
killrvideo.videos
WHERE solr_query='{ "q": "{!
edismax qf="name^2 tags^1
description"}datastax" }';
SELECT id, value FROM
keyspace.table WHERE token(id)
>= -3074457345618258601 AND
token(id) <=
3074457345618258603 AND
solr_query='id:*'
28. Confidential
Behind the scenes…
28
// Videos by id
CREATE TABLE videos (
videoid uuid,
userid uuid,
name text,
description text,
location text,
location_type int,
preview_image_location text,
tags set<text>,
added_date timestamp,
PRIMARY KEY (videoid)
);
// Index for tag keywords
CREATE TABLE videos_by_tag (
tag text,
videoid uuid,
added_date timestamp,
userid uuid,
name text,
preview_image_location text,
tagged_date timestamp,
PRIMARY KEY (tag, videoid)
);
Not a great idea
Possible Index
29. Confidential 29
//Videos by id
CREATE TABLE videos (
videoid uuid,
userid uuid,
name text,
description text,
location text,
location_type int,
preview_image_location text,
tags set<text>,
added_date timestamp,
PRIMARY KEY (videoid)
And
this?
This?
This?
31. Confidential 31
1) Spin up a new C* Cluster with search enabled using the DSE
installer.
$ sudo service dse cassandra -s
2) Run your schema DDL to create the C* keyspace and tables.
3) Run dse_tool on the videos table
$ dsetool create_core killrvideo.videos generateResources=true
4) Use the Solr Admin to check sanity and make sure you have a
core.
5) Write a CQL query with a Solr Search in it.
SELECT * FROM killrvideo.videos
WHERE solr_query='{ "q": "{!edismax qf="name^2 tags^1 description
"}datastax" }';