137

I am learning NoSQL and looking at different options for one of my client's requirements. I have gone through various resources before putting up this question (a person with little knowledge in NoSQL)

  • I need to store data at faster rate and read data.
  • Fully fail-safe and easily scalable.
  • Able to search through data for Analytics.

I ended up with a short list of: Cassandra and Elasticsearch

What I do understand is Cassandra is a perfect NoSQL storage solution for me, as I can write data and read data using indexes. Where it fails or it could fail is on Analytics. In the future, if I want to get data from from_date to to_date, or more ways to get data for analytics, if I don't design the Data model properly or keeping long term sight, which might be quite hard in ever changing world.

While Elastic Search is best at indexing (backed by Lucene), and can search the data randomly by throwing some random text. But does it work the same for even if I want to retrieve data from_date to to_date (I expect it might be). But the real question is, is it a Search Engine, or perfect NoSQL data storage like Cassandra? If yes, why do we still need Cassandra?

If both of these are in different world, please explain that! How do we combine them to get a more effective solution?

user7337271
  • 1,662
  • 1
  • 14
  • 23
RaceBase
  • 18,428
  • 47
  • 141
  • 202
  • 2
    You should consider also DSE Search = Cassandra + solr integrated = best of both worlds: a scalable db for the storage driven by the search power of Solr. – Bereng Nov 21 '14 at 08:29
  • 1
    @Bereng, I guess DSE is commercial and we are not looking after commercial softwares. – RaceBase Nov 21 '14 at 09:06
  • 3
    If you are a startup with net revenues < $2 million (US), they will let you use DSE free of charge (for at least a year or two). – Aaron Nov 21 '14 at 23:00

8 Answers8

175

One of our applications uses data that is stored into both Cassandra and ElasticSearch. We use Cassandra to access those records whenever we can, and have data duplicated into query tables designed to adhere to specific application-side requests. For a more liberal search than our query tables can allow, ElasticSearch performs that functionality nicely.

We have asked that same question (of ourselves)..."Why don't we just get everything from ElastsicSearch?"

The answer is that ElasticSearch was designed to be a search engine, and not a persistent data store. Sometimes ElasticSearch loses writes. Schema changes are difficult to do in ElasticSearch without blowing everything away and reloading. For that purpose, I have written jobs that are designed to keep ElasticSearch in-sync with our Cassandra cluster. There was also a fairly recent discussion on Quora about this topic, that yielded similar points.

That being said, ElasticSearch works great as a search engine. And Cassandra works great as a scalable, high-performance datastore. But querying data is different from searching for data. There are times that we need one or the other, and a combination of the two works well for our application. It may (or it may not) work well for yours.

As for analytics, I have had some success in using the Cassandra Spark connector, to serve more complex OLAP queries.

Edit 20200421

I've written a newer answer to a similar question:

ElasticSearch vs. ElasticSearch+Cassandra

starball
  • 20,030
  • 7
  • 43
  • 238
Aaron
  • 55,518
  • 11
  • 116
  • 132
  • 33
    Can someone elaborate on the difference between *querying* and *searching* the data? – Dror Aug 11 '15 at 12:14
  • 29
    @dror for example if you know the id(s) of your data you just ask for it (cassandra) and if you don't know the id(s) of your data then you search for it/them (elastic search). – arsenik Aug 15 '15 at 13:00
  • @arsenik Well I can do search in cassandra using Spark DataFrame with something similar to SQL LIKE command. I suppose by searching in elasticsearch you mean something more advanced. Am I right? – M.Rez Jun 21 '16 at 18:44
  • @M.Rez yes elasticsearch is one search engine which can be used to retrieve id(s) – arsenik Jun 21 '16 at 20:25
  • @arsenik regarding the difference between querying and searching I don't agree, to me I have somewhere data and I always do same, I send some command which is here to retrieve data based on my parameters. There is difference in how the data are stored and how can I search/query them. Saying one is doing query and one is doing search is little bit confusing... – kensai Feb 23 '17 at 09:29
  • @Aaron Is this still the case or is it now sensible to use Elastic for all query and search? – Gladwell May 08 '17 at 17:30
  • 2
    @Gladwell it all depends on the size of your data and the complexity of your queries. In theory Elastic can do it all. However, I'd trust Cassandra to do a better job of scaling to support a large data set (for queries) than Elastic, especially if you're supporting multi-region/DC. – Aaron May 08 '17 at 17:52
  • 1
    @Aaron ... scaling to support a large dataset is what both these engines do well. Our organization use elastic search as a primary database, alerting engine, analytics tool, and now that xpack supports machine learning; it also provides business stats around our edge IOT. – AnthonyJClink Mar 03 '18 at 23:54
  • @AnthonyJClink Good to know it’s working well for you. Maybe the newer versions of Elastic are pretty solid for durability. But the versions available when I answered this question...not so much. – Aaron Mar 04 '18 at 00:22
  • 1
    @Dror Asking the real question! – Mike Ezzati Oct 15 '18 at 18:13
  • 1
    This question needs to be revisited for ES 7.5 – user1870400 Jan 04 '20 at 23:21
33

Cassandra + Lucene is a great option. There are different initiatives for this issue, for example:

edersohe
  • 428
  • 4
  • 4
Alvaro Agea
  • 470
  • 5
  • 8
  • One thing to keep in mind, in 2.1 you can now "drop in" a custom indexer... so for example you could mimic what Statio is doing with their fork of C* but off of mainline C*. I am not aware of any widespread efforts to do this, but I plan on dropping in Lucene indices into C* this way myself. For more info: https://issues.apache.org/jira/browse/CASSANDRA-8717 – Evan Volgas Jul 06 '15 at 18:25
8

After working on this problem myself I have realized that NoSQL databases like casandra are good when you want to make sure you are preserving your data schema with reliable writing operation, and don't want to take advantage of indexing operations that elasticsearch offers. In case you want to preserve some indexes data then elasticsearch is good in case you are trusting your scheme and only going to do far more reads than writes.

My case was data analytics. So I preserved a lot of my Latices in elastic search since later I wanted to traverse through the data a lot to see what should be my next step. I would have used casandra if I wanted to have a lot of changes in the schema of the data in my analytic pilelines.

Also there are many nice representing tools like kibana that you can use to present your data with some good graphics. Maybe I am lazy but they are very good looking and they helped me.

M.Rez
  • 1,802
  • 2
  • 21
  • 30
4

Storing data in a combination of Cassandra and ElasticSearch gives you most functionality. It allows you to lookup key-value tables, and also allows you to search data in indexes.

The combination gives you a lot of flexibility, ideal for your application.

4

Elassandra is the combined solution of Cassandra + Elastic search , It uses Elastic search to index the data and Cassandra as the data store , i'm not sure about the performance but as per this article , its performance is good.
If your application needs search feature then , Elassandra is the best open source option. DSE search is available but its expensive.

anavaras lamurep
  • 1,303
  • 2
  • 17
  • 33
2

We had developed an application where we used Elasticsearch and Cassandra. Similar data was stored into Cassandra and indexed into Elasticsearch.

Our application's UI was having features like searches, aggregations, data export, etc. The back-end microservices were continuously getting huge data (on Kafka topics) and storing it into Cassandra. Once the data is stored into Cassandra, the services would make sure the data is indexed into Elasticsearch.

Cassandra was acting as "Source of truth" for Elasticsearch. In the cases, where reindexing of the ES index was required, we queried Cassandra and reindexed the data into ES.

This solution helped us, as this was very easy to scale and the searches and aggregations were much faster.

Sumit A
  • 170
  • 1
  • 13
2

Cassandra is great at retrieving data by ID. I don't know much about secondary index performance, but I doubt it's as fast as Elasticsearch. Certainly Elasticsearch wins when it comes to full text search functionality (text analysis, relevancy scoring, etc).

Cassandra wins on update performance, too. Elasticsearch supports updates, but an update is really a reindex + soft delete in an atomic operation.

Cassandra has a very nice replication model (if you need to be extra-fail-safe). Elasticsearch is OK, too, I'm not in the camp that says ES is particularly unreliable (it has issues sometimes, like all software).

Elasticsearch also has aggregations for real-time analytics. And because searches are so fast, analytics on a subset of data will be fast, too.

If your requirements are satisfied well enough by one of them (like here it seems like ES would work well), I would just use one. If you have requirements from both worlds, then you can either:

  • use one of them and work around the downsides. For example, you may be able to handle many updates with Elasticsearch, but with more shards and more hardware
  • use both and make sure they're in sync
Radu Gheorghe
  • 984
  • 9
  • 6
0
  • As elasticsearch is built on Lucene index and if you want to store indexing in elasticsearch it performs best comparing to indexing in Cassandra itself for retrieving the data.
  • If your requirements are not related to real-time retrieval then you can use elasticsearch as NoSQL database also, there are thoughts that ElasticSearch loses writes & Schema changes are difficult, but if your volume of data is not too big. You can easily achive elasticsearch as a search engine with best indexing along with elasticsearch as aNoSQL database. There are several way that you can prevent it. I have worked on the schema changes in elasticsearch, if your data structure is consistent then it will create any issues.
  • Being a supporter of ElasticSearch or SOlr. I have worked on both the search engines and i experienced that both the search engines can be used fluently if you configure them correctly.
  • Only cons that i can think of it, if you are targetting real time result and can't comprosie milliseconds delay in your response. Then its better to take help of other NoSQL databases like cassandra or couchbase.
  • Cassandra with solr, work better than Cassandra with elasticSearch.
vishal yadav
  • 93
  • 1
  • 7