Choice in the database market has never been so great, especially when it comes to document databases. Should you go with MongoDB or Amazon’s DocumentDB? Is Couchbase the right fit for you?
One solution that has become popular is Elasticsearch. At first glance it’s another NoSQL database storing data as JSON documents. If you load their Shakespeare sample dataset into Elasticsearch you can write queries like the following:
GET shakespeare/_search { "query": { "term": { "play_name": { "value": "Twelfth Night" } } } }
This will return all the documents relating to Twelfth Night. But this is something any document database can do, so why would you choose Elasticsearch?
The answer comes when you start to understand the technology behind it. Elasticsearch is a distributed full-text search and analytics engine backed by Lucene. Or in other words it allows you to search through your data in a very similar way to any search engine, returning results ranked by how closely they match the search term. Rather than asking for all the characters within a play like Twelfth Night, the question it can answer is which play has a phrase a bit like “when shall we meet again”.
The query for that question looks like this:
GET shakespeare/_search { "query": { "multi_match": { "query": "when shall we meet again", "fields": [ "text_entry" ] } } }
Unsurprisingly, the highest ranked result is Macbeth with the line “When shall we three meet again” which has a score of 23.668333. However, Romeo and Juliet has the line “Farewell! God knows when we shall meet again” (score 21.306107), and Troilus and Cressida has the line “When shall we see again?” (score 18.1719915).
In a business setting a useful piece of functionality might be a free text search which allows users to search through various pieces of data. E.g. a salesperson remembers talking to a client about an issue and adding some notes to their profile, but they can’t remember which client it was, or perhaps searching through an archive for documents containing certain keywords or phrases. Elasticsearch is a technology that could help with this.
At Elastic Mint we pride ourselves on helping customers choose the right technology for their problem. How can we help you?