Elasticsearch: 3 Awesome Unknown features You Must Check Out Today.

Knowing them can literally change your Elasticsearch journey.

Photo by Andrea Piacquadio from Pexels

In this article, I’ll be sharing with you three (03) wonderful Elasticsearch features I came across while learning and using it. This article will be short but truly full of new stuff about Elasticsearch. Are you ready? Let’s dive right in.

1- Search-As-You-Type Field Type

I’m pretty sure you’ve seen and used autocomplete features on a lot of websites, social media, simple and advanced web applications like Google, Facebook, Amazon, Tiktok, and so on.

Well, think of implementing this just through a special type of field. It may sound unrealistic but Elasticsearch makes it easy for you to implement an autocomplete search just with a special type of field.

Elasticsearch suggests to you the entries that match your input while you’re typing and this is done through a type of field called Search-As-You-Type. It’s the perfect way for you to implement a real-life auto-completion system without worrying too much about how the search works under the hood.

To know more about how to use it, check this out: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html

2- N-gram

I’m quite sure that you came across the same search issue I went through in the earlier days of my journey working with Elasticsearch. Let me show you something.

Let’s assume that you have this document in your Elasticsearch index:

{
"title": "How Trump became a president.",
"description": "You'd better do something else than trying to figure it out",
"date": "2005-04-04"
}

Then let perform a simple search again that index to find this document.

curl -XGET -H "Content-Type: application/json" "127.0.0.1:9200/articles/_search?pretty" -d 
'{
"query": {
"term": {
"title": "Trum"
}
}
}'

What did you get from Elasticsearch? Yes, an empty result. And I saw so many software engineers complaining about this on Stack overflow. One of the solutions for that issue is simply what we call the n-gram algorithm.

An n-gram is a contiguous sequence of n items from a given sample of text. Elasticsearch has got an N-gram token filter and an N-gram tokenizer to help you to implement a custom analyzer.

To know more about Elasticsearch N-gram features, check these links out :

3- Highlighting

As Elasticsearch users, we got accustomed to those autocompletion entries containing bold parts while typing either in a search engine search bar or a browser search bar. Do you know that Elasticsearch allows you to do this on every query you make without any required customization from your side (front or backend)?

Yes, I know it seems unbelievable till you see it in action. Let’s quickly give it a go.

GET /_search
{
"query": {
"match": { "tag": "youtube" }
},
"highlight": {
"fields": {
"content": {}
}
}
}

The above query allows you to highlight search results on the tag field. Elasticsearch will enlight every term youtube found in the tag field contents.

Isn't that brilliant? I’m quite sure you want to dive deeper into this feature that Elasticsearch offers. If so check this:

Conclusion

In this article, we walked through three less known but nice features Elasticsearch offers to engineers.

I really want you to check all these out for more details and for the sake of practicing or trying. Then when the time comes to take advantage of any one of them, you won’t lose time at all. They’ll come into your mind at the right moment and on the right occasion.

I hope you liked this article. Till next time, take care!

Certified AWS Solution Architect, Fullstack Software Engineer & DevOps. I like Solving Challenging Software Engineering Problems & Building Amazing Solutions.