Replace Elasticsearch with MeiliSearch

Data really powers everything that we do – Jeff Weiner

Data is everywhere and there is no doubt that the datasets we now spans gigabytes easily. We live in a data-rich world. Everyone is on the internet and getting meaningful information from queries this data set is critical. Most of the time they get overwhelmed with the data and have trouble finding what they are looking for. Here comes the Search Engines which is designed to search for websites on the internet based on the user's search query.

With the success of Elasticsearch, many smaller search engine options have popped up. One of the most popular of these options is MeiliSearch. While smaller options are usually considered to be weaker than their larger counterparts, this is not necessarily the case with MeiliSearch. MeiliSearch has received praise for its speed and accuracy, given that it takes up much less resources than Elasticsearch. So, if you're not ready to take the plunge into Elasticsearch-based search engines, MeiliSearch might be the perfect fit for your application.

  1. What is MeiliSearch?
  2. What is Elasticsearch?
  3. Difference Between Elasticsearch and MeiliSearch
  4. Features In MeiliSearch

#1 What is MeiliSearch?

MeiliSearch is an open source search engine that has been designed from the ground up with the goal of being the fastest search engine in the market which was developed by Quentin Dequelen and Clement Renault in the year 2018. It is written in Rust, a blazingly fast and memory-efficient programming language. MeiliSearch is also very easy to set up and can be installed in just a few minutes on your server. It will index your sites and make them searchable almost immediately.

It delivers an instantaneous and intuitive search experience for users. It provides search-as-you-type-experience which means it delivers results at < 50 milliseconds also returns result for EVERY keystroke. It is highly customizable and supports Faceted search and filters, synonyms, kanji characters, placeholder search and typo tolerant i.e. it understands typo errors and misspelling. It cracks the friction between the end-user and your website by providing instant search method.

Let us search for the word "Developer" contained in the field called "position" in the employee documents.

curl 'http://127.0.0.1:7700/indexes/employees/search' \
        --data '{ "q": "Developer" }'

In Meilisearch, you pass a simple query param to filter the documents, not like JSON in Elasticsearch. The index in MeiliSearch is comparable to a table in SQL, or a collection in MongoDB.

#2 What is Elasticsearch?

Elasticsearch is a distributed, RESTful, free, powerful open-source, search and analytics engine which developed built in Java and released by Elasticsearch N.V. It supports all kinds of data like textual, numerical, geospatial, structured, and unstructured. It is the most popular search engine in recent days which supports large number of datasets.

For indexing and searching Elasticsearch uses Apache Lucene as its core, takes unstructured data as input and stores it in a sophisticated format which is then used for language based searches. It provides an API which comes in the form of HTTP RESTful API which uses JSON as data exchange format. The performance is based on the scenarios and the volume of data, and the rate at which applications and users query your data.

Let us search for the word "Developer" contained in the field called "position" in the employee documents.

POST employees/_search
{
  "query": {
    "match": {
      "position": {
        "query" : "Developer"
      }
    }
  }
}

#3 Difference Between Elasticsearch and MeiliSearch

The first and foremost step in using a search engine is learning about how to install and configure it in our machine. You would get surprised that Elasticsearch has a very deep learning curve whereas MeiliSearch literally has zero configuration and so it is easy to set up and use. Elasticsearch is made to be complex and large scale, since it can handle many documents and data types, which is great if you have a huge database and need to search it all at once. The problem in using Elasticsearch for a handful number of datasets is quite difficult since it doesn't perform as expected. Here comes our MeiliSearch, which can be used to get instant search results which provides blazing fast performance.

For 15k documents with 70 pages each Elasticsearch would use around 1 GB RAM in development and 1 - 1.5 GB RAM when used in production whereas MeiliSearch uses just 140 MB RAM. Sounds great right!!! 😇

Elasticsearch handles search through enormous amount of data and performs analysis. To make it more efficient and effective you will need to learn and understand how it works internally to customize anything in it. Most of the time it returns slower search result while using full text search when compared to Meilisearch. Meilisearch is a easy tool to deploy a typo-tolerant search bar that provides a prefix searching capability, makes search intuitive for users, and returns them their results instantly with near-perfect relevance.

#4 Features In MeiliSearch

Let us dig deep into the features of MeiliSearch before using it.

  • Search-As-You-Type - This makes searching simple and responsive, since it returns results at every keystroke of any user. This helps users save their time and can iterate on their searches.
  • Typo Tolerant - Need not to worry if you make spelling mistakes in any of your search. Meilisearch automatically corrects the typos and search based on it. Avoid letting typos ruin your search experiences with Meilisearch. It uses a prefix Levenshtein algorithm to check whether the word matches or not.
Levenshtein Distance
  • Faceted Search - It is a guided navigation where users can use this to refine their queries and category listings. Fields with common values are used as facets for example movie, genre, color, gender, age etc.. It is a powerful feature which allows building intuitive navigation interfaces.
  • Bucket Sort - Search results are sorted according to some criteria or defined ranking rules. These rules can be customized by deleting and adding new ones based on your preferences. By default MeiliSearch sorts search result in the following order - Typos, Words, Proximity,  Attribute, Word Position, Exactness.
  • Concatenate Queries - Have you ever wondered about the best way to combine keywords in a search query? Most search engines apply a simple concatenation algorithm and combines multiple query terms into a single, longer term. This is useful for queries with a high number of ambiguous terms. The goal of concatenation is to capture a user’s intent more accurately by combining commonly used terms.
  • Synonyms - You can create a list of synonyms i.e words that are similar to another word or have a related meaning. This will return more relevant search result.

Example:  Here are the set of synonyms for employee, staff.  

{
  "Employee": ["Staff"],
  "Staff": ["Employee"]
}

When you search for employee MeiliSearch would return documents containing employee as well as the documents with Staff.

  • Snapshots - It is the precise copy of the database. These can be thought as "pre-compiled copies" since they do not undergo any other processing rather than compression. You can use the existing snapshots to restore MeiliSearch by scheduling the snapshot creation at custom intervals. These snapshots are created once MeiliSearch is launched and are created frequently based on the set interval.
  • Distinct Attribute - It is a field whose values will always be unique in the search results. This avoids duplicates i.e documents with same value of that field will not be returned.  

Example: Here are two documents that contains information about same fruit with different colors.  

[
  {
    "id": 1,
    "description": "Grapes",
    "color": "Green",
    "product_id": "123456"
  },
  {
    "id": 2,
    "description": "Grapes",
    "color": "Black",
    "product_id": "123456"
  }
]

You can set product_id as distinct attribute so when you search for grapes it will return only the unique values.

  • Dumps - It is a compressed file containing the export of MeiliSearch instances. It comprises of raw unprocessed data such as indexes, documents and settings which helps you in creating identical datasets and hence it is called as blueprint.
  • Filtering - Meilisearch offers filtering to help users find their desired information in a large dataset.

Is Meilisearch better than Elasticsearch??

Most people think of search as a way to find information on the Web, but there are many other kinds of searches and not all of them are the same. Searching to find information is usually a one-time thing. Other searches are for things that are tried and true, and you can use them every day. If you’re looking for something new to try, like a restaurant in a city you don’t know well, a new food in a cuisine you’re not familiar with, chances are you’re looking to search for something new. There’s a very basic question behind every search thus try it out and choose which one would fit your needs. I would suggest using MeiliSearch for its better performance and friction-less end-user experience.

In actuality, there isn’t just one best search engine for you. Instead, the answer depends on what you’re searching for. MeiliSearch is better for small to medium scale businesses who uses smaller number of datasets. If you want a better search experience for your end-users with datasets that contains large number of keywords you can choose MeiliSearch. Deliver better search experience for your customers with Meilisearch!!