Member-only story

Best Practices of Using ElasticSearch

Explaining how to use ElasticSearch in a better way

Chunting Wu
6 min readJun 5, 2023
Photo by Geometric Photography on Unsplash

Last time, we have introduced some tips for boosting ElasticSearch performance.

In addition, that article explains the underlying details of ElasticSearch. This time, we are going to talk a little more about best practices for using ElasticSearch.

These practices are general recommendations and can be applied to any use cases. Let’s go.

  • Bulk Requests: The Bulk API makes it possible to perform many index/delete operations in a single API call. This can greatly increase the
    indexing speed. Each subrequest is executed independently, so the failure of one subrequest won’t affect the success of the others. If
    any of the requests fail, the top-level error flag is set to true and the error details will be reported under the relevant request.
  • Multithread clients to Index Data: A single thread sending bulk requests is unlikely to be able to max out the indexing capacity of an
    ElasticSearch cluster. In order to use all resources of the cluster, you should send data from multiple threads or processes. In addition to
    making better use of the resources of the cluster, this should help reduce the cost of each fsync. Both the index data and transaction log
    are periodically flushed to disk. If there are more data with multithread, the more data is synced to disk to reduce I/O to improve
    performance.
  • index.refresh_interval: By default, ElasticSearch periodically refreshes indices every second, but only on indices that have received one
    search request or more in the last 30 seconds.This is the optimal configuration if you have no or very little search traffic (e.g. less than
    one search request every 5 minutes) and want to optimize for indexing speed. This behavior aims to automatically optimize bulk indexing
    in the default case when no searches are performed. In order to opt out of this behavior set the refresh interval explicitly. On the other
    hand, if your index experiences regular search requests, this…

--

--

Chunting Wu
Chunting Wu

Written by Chunting Wu

Architect at SHOPLINE. Experienced in system design, backend development, and data engineering.

No responses yet

Write a response