Cassandra with lucene on docker
Full text search with cassandra
The part time parliament
I have done a talk The part time parliament
. Its about cassandra and lucene plugin integration to achieve full text search. This post contains main areas that I have covered in the talk. You can find the slides of my talk from here.
About cassandra
Cassandra is distributed NoSQL
data storage built by facebook. Main motivation of cassandra is to build distributed database with high availability
and scalability
.
By default cassandra does not provide full text search(means search by all fields in a table like relational database). Cassandra only capable to query via primary indexes and secondary indexes. To achieve full text search we have used cassandra lucene plugin
.
Lucene plugin
We can create lucene indexes via lucene plugin. Lucene indexes are extension of cassandra secondary indexes which creates via CQL CREATE CUSTOM INDEX
statement. By using lucen indexes we can do realtime searches with cassandra like ElasticSearch
or Solr
. More information about cassandra lucene plugin can be find from the documentation
Dockerize cassandra with lucene
Following is the docker file I have written to dockerize cassandra with lucene plugin.
Full source available on my github
Build docker
docker build erangaeb:cassandra:0.1
Run docker
docker run -p 9160:9160 -p 9042:9042 erangaeb/cassandra:0.1
Connect via cqlsh
After run the docker container you can connect to it via cqlsh. You have to install cqlsh in your local machine
Cassandra lucene usage
Create keyspace and table
First we have to create cassandra keyspace and table. I’m creating simple table document
here.
Search via primary key
Cassandra only allows to search via primary index. In above table via id
field. If we try to search with any other filed it gives an error
Create lucene index
To search via other fields we can create lucene indexes with other fields.
Lucene query
After creating lucene indexes, we can execute lucene queries to search by any given filed.
Lucene with cassandara user define types
Lucene search can be integrated with cassandra user define types
as well.