Elasticsearch for Magento 2

Magento 2 Elasticsearch: Configuration and Optimisation

As your Magento 2 store scales, search speed and relevance become critical to customer experience and conversion rates. That’s where Elasticsearch (ES) comes in — a powerful distributed search and analytics engine that, when configured correctly, can dramatically enhance your store’s performance.

In this guide, we’ll walk you through the key components, configuration steps, optimisation techniques, and real-world case studies to help you get the most out of Elasticsearch in a Magento 2 environment.


Understanding Elasticsearch Architecture

Before diving into configuration, it’s vital to grasp how Elasticsearch works within Magento:

  • Indices: Logical groupings of similar documents (e.g., products, categories). Magento typically creates separate indices, such as magento2_product_1.
  • Shards: These store actual data and are the units that queries run against. Shards can be distributed across nodes for scalability.
  • Nodes: Individual Elasticsearch instances that manage data and processing.
  • Cluster: A collection of nodes working together, forming a scalable and fault-tolerant search backend.

A. Magento Admin Configuration

1. Enable Elasticsearch

Navigate to:
Stores > Configuration > Catalog > Catalog Search
Set the Search Engine to Elasticsearch 7.x and configure the necessary server details:

  • Host
  • Port
  • Index Prefix
  • Timeout

2. Manage Indexes

Set Indexer Mode to Update on Schedule to allow asynchronous indexing.
Reindex manually via CLI when needed:

php bin/magento indexer:reindex catalogsearch_fulltext

For more on working with Magento APIs and advanced configurations, read our guide on Extension Attributes in Magento 2 APIs.


B. Elasticsearch Server Configuration

1. elasticsearch.yml – Key Settings

cluster.name: magento-cluster
node.name: node-1
network.host: 0.0.0.0
discovery.seed_hosts: ["node1.ip:9300", "node2.ip:9300"]

2. Performance Tuning

  • Set Heap Size to ≤ 50% of total RAM in jvm.options:
    -Xms4g -Xmx4g
  • Disable swapping:
    bootstrap.memory_lock: true

3. Install Plugins

To support multilingual search, install the ICU Analysis plugin:

bin/elasticsearch-plugin install analysis-icu

Optimisation Techniques

A. Indexing Optimisation

  • Increase Batch Indexing Size to 500–1000 in Magento Admin.
  • Use parallel processing:
php bin/magento indexer:reindex --all --parallel

B. Search Query Optimisation

Edge N-Gram Tokenisation

Use a custom analyser for better partial match search:

{
"settings": {
"analysis": {
"analyzer": {
"magento_edge_ngram": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "magento_edge_ngram"]
}
},
"filter": {
"magento_edge_ngram": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10
}
}
}
}
}

Field Boosting

Prioritise fields like product names over descriptions to improve relevance.

C. Performance Tuning

  • Refresh Interval: Increase during bulk indexing:
PUT /magento2_product_1/_settings
{ "index.refresh_interval": "30s" }
  • Merge Policy:
PUT /_cluster/settings
{
"persistent": {
"indices.merge.scheduler.max_thread_count": 1
}
}

D. Scaling

  • Add nodes to horizontally scale your cluster.
  • Allocate 1–2 shards per GB of data to avoid overloading.

Real-World Case Study: Large Catalogue Store

Challenge:
50,000+ SKUs, sluggish search and high CPU usage.

Solution:

  • Upgraded to Elasticsearch 8
  • Set JVM heap to 50% RAM
  • Implemented custom analyzers
  • Tuned Magento’s search settings

Results:

MetricBeforeAfter
Search Latency (ms)800ms450ms
CPU Usage (%)90% peak60% peak
Bounce Rate (%)35%25%

Debugging & Monitoring

  • Fix Read-Only Index Errors:
PUT /_all/_settings
{ "index.blocks.read_only_allow_delete": null }
  • Prevent Circuit Breaking:
indices.breaker.fielddata.limit: 60%

Recommended Tools:

  • Kibana or Cerebro for cluster monitoring
  • TLS/SSL & Role-Based Access via OpenDistro Security
  • Test all changes in a staging environment first

Conclusion

Optimising Elasticsearch for Magento 2 isn’t just about setup — it’s about creating a scalable, responsive, and intelligent search system that grows with your business. From sharding strategies to fine-tuned analyzers and scalable clusters, each step contributes to delivering lightning-fast search and a smoother customer journey.

Want to take your Magento 2 setup even further? Learn how to enable B2B features in Magento 2 or explore the future of eCommerce in our article on Magento and the Metaverse.


Need help with Elasticsearch optimisation or Magento customisation?
Get in touch with the experts at Kiwi Commerce — we help you build smarter, faster Magento solutions.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *