Elasticsearch

Elasticsearch For Real-Time Search And Analytics: How and Why?

Tuesday, 9 June, 2015 Updated on Thursday, 8 July, 2021 by Eton Digital team

Elasticsearch (ES) is a popular, highly scalable open source search and analytics engine, but why should you use it? And how?

Our web developer Milos Milojevic explains why and how. Milos has vast experience in PHP and.NET development, Matlab programming, CGI, C# and C++, and has worked with Symfony, Zend, Codeigniter, Yii and more PHP frameworks.

Read on to see why you should use ES, and look at how we use Elasticsearch to enhance our web projects.

First things first: Why Elasticsearch?

Elasticsearch is a powerful open source search engine built on top of Apache Lucene.

Firstly, being an open source is a significant advantage of ES.

Secondly, ES makes data aggregation and querying easy and simple.

In a word, ES offers a lot of functionalities, it’s easily customizable, fast and efficient.

Many benefits and qualities set ES apart from other search servers; these are the qualities I believe are important to highlight (especially for developers):

  • ES provides good experience in every aspect
  • It’s easy to use, administer and manage
  • The server allows multiple types of documents in a single index
  • ES provides easy search across multiple indexes
  • It combines results from different fields, automatically
  • You can easily define your mapping
  • It offers easy 3rd-party integration (Drupal, Symfony2, Django, WordPress, CouchBase)
  • You can easily integrate ES with data sources and additional indexes, due to flexible API
  • With a simple HTTP command, you can create, open, close and delete indices

However, whether you start using ES or not, largely depends on your specific application.

On the other hand, different industries and many high-profile companies are leveraging the power of search with ES – GitHub, StackOverflow, Wikipedia, StumbleUpon, LinkedIn, WordPress, Target, eBay, to name a few.

How do we use Elasticsearch?

The quality product is focused on usability.  We choose Elasticsearch as it’s a fast search engine (and nothing can destroy usability as fast as slow performance) and it can be accessed using both search-specific methods and regular database CRUD-like commands.

Another important factor in choosing the search server is scalability, and ES has excellent scalability options. It’s a fast server able to store all types of data, and this is the reason ES plays a big part in providing the best customer experience. For some of our clients, real-time updating (fast indexing) is very important, and ES offers this through various functionalities. With ES you can group any data and search by relevance, which is very lucrative when searching for different content on your application.

We create bespoke social networks; SN development is our expertise. For any social network, content searching and sharing is paramount, and for the best experience, we use ES.

It’s highly flexible, and it can be customized for advanced text searching. The server analyzes different variations of the word you are searching (partially written words, misspelling, synonyms) for the best match. This is another powerful feature of Elasticsearch.

Particular features that are especially helpful

Elasticsearch provides lots of features one can use for web applications; it allows everything from simple search queries to system management.

Let’s take StackOverflow for example. If you are searching title in autocomplete to find similar questions on StackOverflow, you can index the title for each question or create a group of text fields in one index. So, when you are searching for a specific phrase or only a part of the question, the server will search all text fields and sort and return data by relevance.

Logstash and Kibana are very useful products; with these tools, you can manage large lists of logs and monitor your data with powerful graphics. Logstash is a tool for receiving, collecting, processing and outputting logs. Kibana is for searching and data visualization.

Another very useful feature is Percolator;  it works in real time and provides subscription type functionality. By using Percolate API, you can search faster, store your search queries into indexes and get them automatically extracted from the document.

ES has built-in clustering support, within one cluster you can run ES on lots of servers and still perform an effective search.

Autocomplete in ES is fast and effective. Once you type in a keyword, ES query will provide all suggestions that exist in the index (you can additionally create a specific filter for indexing).

In Elasticsearch it’s very easy to define your mapping because all you have to do is to create correct JSON format with your mapping configuration.

Here is an example of how to create mapping via curl function:

mapping via curl function

As we use FOSElasticaBundle for indexing and querying, ES fits well with the company’s architecture.

Here is an example of search queries with FOSElasticaBundle, by using search finders.

Elasticsearch queries with FOSElasticaBundleFOSElasticaBundle provides already developed services for searching and indexing content is also very easy as it is connected with objects. The developer simply needs to configure which fields are required – a simple command from a terminal will index all the fields. A significant advantage is seen in good documentation, which is very important.

ES is simple to use, once you download the archive, unpack it, and use a script to start it.

If you are considering ES be prepared to learn a lot, although it can be sometimes hard to define what you need to learn; however, different usage comes with different levels of complexity and resource requirements.

Many competing search servers offer similar features, and it might be difficult to decide on one or the other – the best way to decide is by knowing the requirements of your organization and the project.

We’d love to work with you on your project!

Get in touch with us and tell us your idea.

Start a project