Back to blog
Performance

10 Elasticsearch Performance Tuning Tips

The biggest Elasticsearch performance wins come from right-sized shards (10-50GB), correct field types, filter context, bulk indexing, and leaving heap auto-sizing on.

Abhilash BUpdated 3 min read
#elasticsearch#performance#optimization#tuning

Most Elasticsearch performance problems come down to a handful of fundamentals: shards sized between 10GB and 50GB, the right field types, filters instead of scored queries where scoring doesn't matter, bulk indexing, and enough memory for both the heap and the filesystem cache. Here are ten tips, in roughly the order we check them.

1. Optimize your index settings

Start with the right index settings for your use case. Consider the following:

  • Number of shards: Don't over-shard your indices. Elastic's guidance is to aim for shard sizes between 10GB and 50GB and to keep each shard below 200 million documents.
  • Number of replicas: Balance between search throughput, resilience and storage costs.
  • Refresh interval: Increase the refresh interval for indices that don't need near real-time search.
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval": "30s"
  }
}

2. Use appropriate field types

Choose the right field types for your data:

  • Use keyword for exact matches, aggregations and sorting
  • Use text for full-text search
  • Use date for temporal data
  • Use dense_vector (or semantic_text) for semantic search

3. Implement proper mapping

Design your mappings explicitly rather than relying on dynamic mapping:

{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "standard"
      },
      "category": {
        "type": "keyword"
      },
      "created_at": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}

4. Optimize query performance

  • Put non-scoring clauses in filter context: filters skip scoring and Elasticsearch caches frequently used ones
  • Use bool queries efficiently
  • Avoid leading-wildcard queries on large datasets (consider index_prefixes for prefix search)
  • Avoid scripts in sorting, aggregations and script_score where you can

5. Monitor cluster health

Regular monitoring is essential:

  • Track cluster status and node health
  • Monitor query performance metrics and the slow log
  • Set up alerts for critical thresholds
  • Use Elasticsearch's built-in monitoring

6. Implement index lifecycle management (ILM)

Automate index management:

  • Hot phase: actively updated and queried
  • Warm phase: updated rarely or not at all, still queried
  • Cold phase: updated rarely, queried infrequently
  • Frozen phase: no longer updated, queried rarely (searchable snapshots)
  • Delete phase: automatic cleanup

7. Optimize hardware resources

  • Let Elasticsearch size the JVM heap automatically (the default, based on node roles and memory). If you set it manually, keep it at or below 50% of the node's memory and below the compressed-oops threshold (26GB is safe on most systems), with Xms equal to Xmx
  • Leave plenty of memory for the filesystem cache, which search relies on heavily
  • Use SSDs for better I/O performance
  • Distribute load across multiple nodes
  • Use dedicated master-eligible nodes for large clusters

8. Use bulk operations

Batch your operations for better performance:

const operations = documents.flatMap(doc => [
  { index: { _index: 'my-index' } },
  doc
]);

await client.bulk({ operations });

9. Implement proper security

  • Keep authentication and authorization on (security is enabled by default)
  • Use TLS encryption
  • Implement field- and document-level security where needed
  • Run regular security audits

See our Elasticsearch security best practices for detail.

10. Plan for scaling

  • Design for horizontal scaling
  • Use cross-cluster replication for disaster recovery
  • Take regular snapshots
  • Plan capacity based on growth projections

Conclusion

Following these performance tuning tips will help you build a robust, scalable Elasticsearch implementation. Remember to test changes in a staging environment before applying them to production.

For more advanced optimization strategies, consider working with Elasticsearch experts who can provide tailored solutions for your specific use case.

Sources

Advisor, Query Quotient

Abhilash B is an advisor at Query Quotient and an information retrieval and AI expert who holds patents in the field. Abhilash brings that retrieval depth to the search, RAG and agent systems Query Quotient builds for clients.

Keep reading

Building something similar?

Tell us what you are working on. In a free 30-minute call we will give you an honest view of the approach, the effort and how to measure success.