What is Elasticsearch and why is it so fast

Let’s start our journey with Elasticsearch

Lynn Kwong

--

Elasticsearch is the most popular open-source enterprise search engine based on the Lucene library, which allows the creation of indices on every field of a document by default. Another popular search engine based on the Lucene library is Apache Solr.

Photo by Mick Haupt on Unsplash.

Solr is a mature and also widely used search engine. We can’t easily say which one is better and there have been fierce quarrels about this issue. Nonetheless, Elasticsearch is becoming more and more popular and has become the first choice for many companies. Elasticsearch is very easy to install and get started. There is even a company called elastic.co which is dedicated to the creation and maintenance of Elasticsearch deployments.

Besides being a search engine, Elasticsearch is also a distributed document store. Unlike relational databases like MySQL which stores data as rows and columns, Elasticsearch is a NoSQL data store that stores data as JSON documents.

In the aspect of data storage, Elasticsearch is similar to MongoDB which also stores data as JSON documents. However, Elasticsearch and MongoDB are quite different. First, MongoDB is dedicated to data storage, whereas Elasticsearch is to search. Or we can understand in this way that MongoDB is optimized for writing and Elasticsearch is optimized for reading.

In Elasticsearch, all the fields are indexed by default, while in MongoDB you need to create the indices by yourself otherwise the read operation can be slow. Besides, with Elasticsearch, you can use RESTful APIs to do the CRUD operations, while in MongoDB RESTful APIs are not supported, and you need to use the MongoDB domain-specific language to do the CRUD operations.

Why is Elasticsearch so fast? It is because Elasticsearch uses a data structure called an inverted index which supports very fast full-text searches. An inverted index lists every unique word that appears in any document and identifies all of the documents each word occurs in.

By default, Elasticsearch indexes all data in every field and each indexed field has a dedicated, optimized data structure. For example, text fields are stored in inverted indices, and numeric and geo fields are stored in BKD…

--

--

Lynn Kwong

I’m a Software Developer (https://medium.com/@lynn-kwong) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.