How to Improve Elasticsearch Search Performance

How to Improve Elasticsearch Search Performance

Last Updated : May 2020

If you’re suffering from search latency issues and want to improve search performance, Opster’s Search Gateway might be the best solution for you. The Gateway allows for easy detection of slow searches and automated actions to block heavy searches and prevent them from breaking your cluster.

In addition to following the below 10 tips You can also run Opster Elasticsearch check-up which pinpoints issues that cause search latency and provides recommendations on how to improve search performance. It’s a free tool that does not require any installation 

10 tips on how to reduce Elasticsearch search latency and optimize search performance:

  1. Size Parameter

    Assigning a huge value to size parameter causes Elasticsearch to compute vast amounts of hits, which causes severe performance issues. Instead of setting a huge size, you should batch requests in small sizes.

  2. Shards and Replicas

    Optimize necessary index settings that play a crucial role in Elasticsearch performance, like the number of shards and replicas. In many cases having more replicas helps improve search performance. Please refer to Opster’s guide on shards and replicas to learn more.

  3. Deleted Documents

    Having a large number of deleted documents in the Elasticsearch index also causes search performance issues, as explained in this official document. Force merge API can be used to remove a large number of deleted documents and optimize the shards.

  4. Search Filters

    Effective use of filters in Elasticsearch queries can improve search performance dramatically as the filter clauses are 1) cached, and 2) able to reduce the target documents to be searched in the query clause.

  5. Wildcard Queries

    Avoid wildcard, especially leading wildcard queries, which causes the entire Elasticsearch index to be scanned. 

  6. Regex and Parent-Child

    Note that Regex queries and parent-child can cause search latency.

  7. Implementing Features

    There are multiple ways to implement a specific feature in Elasticsearch. For example, Autocomplete can be implemented in various styles. Opster’s blog gives a 360-degree view of both functional and non-functional features (especially performance).

  8. Multitude of Small Shards

    Having many small shards could cause a lot of network calls and threads, which severely impact search performance; please refer to this real-world case study by Opster’s expert on this topic.

  9. Heavy Aggregations

    Avoid heavy aggregations that involve unique IDs. Refer to Opster’s  slow logs guide to identify such search slow logs effectively. 

  10. Timeout and Terminate

    Timeout param and terminate after param can be useful when executing heavy searches, or when result data is vast. This official guide can help.