Dynamically add new fields to Elassandra

(λx.x)eranga
Effectz.AI
Published in
2 min readApr 15, 2019

About elassandra

Elassandra is a distributed storage which built with combining elasticseachwith cassandra. It comes elasticsearch as a cassandra plugin. Basically it has cassandra API as well as elasticsearch API. When data save on cassandra it will automatically index on elasticsearch. It’s an ideal and powerful solutions to achieve full text search on cassandra. Read more about elassandra from here.

Scenario

I have have a cassandra table vendors(oui, name, enabled, timestamp) on elassandra cluster. Following is the cassandra schema that I have used to create the vendors table.

I have created vendor elastic index for this table as well. Following is the elastic index of vendors.

I want to add new email filed to this vendor cassandra table and sync it with elasticsearch. Just adding email field to cassandra table not automatically reflect in the elastic index. We have to manually update the elastisearch mapping. Following is the way to do that.

Add email filed to cassandra table

To add the filed to cassandra table we can simply execute ALTER query with cqlsh. Following is the query.

Then we can insert data to vendors table with new email field. For an example I can insert following record.

This email field not yet reflect in the elasticsearch since no elassandra mapping exists for email field in vendors elasticsearch index. If we execute GET query to elasticsearch, it will returns vendor without email field.

Update elasticsearch mapping with email field

We can add email field to vendors elasticsearch index by executing HTTP PUT request on vendors elasticsearch mapping. Following is the way to do that.

Following is the updated vendors elasticsearch index. Now it contains the email field.

Now if you execute GET query to elasticsearch, it will returns the vendor with email field.

Reference

  1. https://github.com/strapdata/elassandra/issues/52
  2. https://github.com/strapdata/elassandra/issues/177
  3. https://medium.com/@itseranga/elassandra-936ab46a6516
  4. https://medium.com/rahasak/migrate-cassandra-data-to-elassandra-1d22adfbf11a

--

--