Search functionality is one of the most important things you need to implement on your website. However, it may be really tough to provide the visitors with a seamless experience. A standard content search may take too long if there are no optimization practices applied, and you can be sure visitors will get irritated by the waiting time.
The newest search engines will be a great help for you when addressing the search-based issues. But there are dozens of suitable tools on the market, and only a few of them can deliver the quality you are looking for. Choosing the right tool is not a piece of cake. So, we decided to share our experience and tell you about the tool that suits us the best.
We tried Apache Solr, database search extensions and many other alternatives. But none of them was powerful enough to enhance the websites we create with excellent performance. After a while, we have come to the choice we would like to recommend. Drupal Elasticsearch appeared to be the best fit as it met all our requirements.
Introduction to Elasticsearch and Its Advantages
You may wonder why we liked it so much. Elasticsearch includes a rather simple RESTful API and easy-to-use JSON payloads. The Drupal Elasticsearch tutorial provides developers with all the needed details and allows applying it to any type of Drupal website. Elasticsearch is incredibly fast and has many other competitive advantages. But let’s start at the beginning and discover its basics.
Here are the top seven things you should be aware of before you start using Drupal and Elasticsearch:
- Elasticsearch is an open-source tool.
- Scalability is one of its greatest features – Elasticsearch is able to scale to 1000 servers or less.
- The capacity is measured in petabytes of data.
- It is based on Lucene, a framework written in Java.
- It operates under the Apache License.
- It is suitable for distributed environments.
- It is the best enterprise search engine.
Elasticsearch is applicable to documents of various formats. It searches indexes instead of text, so the response is instant. The tool offers numerous ways to extend standard search capabilities. You can use it with PHP, Ruby, JavaScript and many other programming languages.
You can use Elasticsearch for full-text search purposes as well.
So, why did we decide on Elasticsearch?
Lucene as the Basis
Lucene is a full-featured library our software engineers are familiar with. It provides an excellent full-text search experience and can be used with different types of open-source products.
Fuzzy Search
Elasticsearch deals with spelling errors quickly. The website users find the needed information even if there is some misspelling.
Instant Search
The tool considerably saves users’ time. It predicts the user’s request and provides the results immediately. While typing, the tool suggests similar requests or existing tags.
If you want to try this feature, just search for something in Google. Google Elasticsearch engine analyzes the search story and suggests the request.
Faceted Search
This method is more effective than a text search. Users can add multiple filters and categorize data. This feature enables better data organization. Additionally, it makes it easier for the user to comprehend and examine the needed data.
Better Speed and Performance
One of the best features we would like to highlight is that Elasticsearch executes even complex queries at great speed. It caches the queries and saves the time other tools spend on parsing.
Elasticsearch stores JSON documents and indexes all the fields, thus providing better performance.
Scalability Features
Elasticsearch allows for horizontal scaling. The tool allows you to get the most out of your resources and maintain the balance between the nodes.
Data Loss Prevention
The tool records the changes applied to nodes. So, you can always use these records to restore lost data.
Precise Results
JSON-based DSL helps to develop complex queries and present users with precise search results.
Elastic Search Index
If the website users are supposed to have access only to their own data, you need to use multiple indexes to hide the information that does not belong to a particular user. Elasticsearch allows using one larger index, which is more convenient.
How to Integrate Elasticsearch with Drupal
Now you know Elasticsearch why can be a great solution for your website. The time has come to find out how to integrate Elasticsearch with Drupal.
There are a few of requirements for the integration:
- Use the latest PHP version (starting from 7.0).
- Install the Elasticsearch 5.0.0 or later versions.
- Install and add Ace Code Editor to the libraries you use and enable /libraries/ace/src-min-noconflict/ace.js.
Here are the step-by-step instructions:
Get Started
Elasticsearch installation essentially doesn’t differ from the installation of any other Drupal 8 module. There are three key steps you need to take in order to start:
- Download the Elasticsearch and extract it from the archive.
- Run it on your Unix or Windows operating system using bin/elasticsearch or bin/elasticsearch.bat respectively.
- Run the curl-X command.
Create a Proof-of-Concept Search
You should make sure the version you have downloaded features the necessary functionality. Besides, you need to exclude the untested features from your code.
The functionality you need includes the pagination, search by value, search by keywords, sorting, and indexing field values. Once you’ve checked this functionality, you can proceed to the next step.
Connect Drupal 8 and Elasticsearch
Now, let’s transmit data from Drupal to Elasticsearch. Search API enables full control over the index via the backend interface. So, first of all, you need to decide on the Search API module.
There are 2 options available: Elasticsearch or Elasticsearch Connector. The second option has several significant advantages:
- It uses the official library.
- It has stronger support.
- It allows creating a whole Elasticsearch ecosystem.
After choosing Drupal Elasticsearch connector, install the Mapper Attachments plugin. Turn on the ElasticSearch Connector Search API submodule to connect the module with the Search API.
Pick the Modules and Dependencies for the Search Setup
We employed the following tools:
Apache TIKA
This is an irreplaceable tool if you want to index the files properly.
Search API Attachment
This is a small search API add-on. It helps to search and index the attached files. You can also use the Search API Attachments Field Collections sub-module to improve the performance.
Search API base64 Encoded Attachments
Search API stores the file with no encoding. This module is the data alteration callback. It dives into search API and adds the special base64 encoding to the files. So, the data sent to Elasticsearch is intercepted by this module and encoded.
Search API Field Analyzer
This module adds analyzers to the defined fields at the moment an index is created.
In Conclusion
It may take time to configure Elasticsearch properly. However, it is worth it, and the final product will demonstrate the expected result. The test search page is multilayered and allows saving search queries and results. At the same time, the interface is quite straightforward and easy to understand. The front-end uses simple custom forms to provide the search results.
Enable Elasticsearch on Drupal website to minimize the amount of effort you need to put in and provide an excellent user experience.
If you are ready for the next step, let’s discuss how Drupal can help your company prosper.