DEV Community

Magevanta
Magevanta

Posted on • Originally published at magevanta.com

Magento 2 Elasticsearch vs OpenSearch: Which to Use in 2026

Magento 2.4.x removed MySQL-based catalog search and made Elasticsearch (or OpenSearch) mandatory. If you're still running MySQL search, you've likely hit Magento's hard block. Here's everything you need to know about the switch.

Elasticsearch vs. OpenSearch: which one?

OpenSearch is a community fork of Elasticsearch 7.10, maintained by Amazon after the license change. For Magento, they're functionally identical — Magento's opensearch engine adapter is based on the Elasticsearch adapter.

Choose Elasticsearch if:

  • You're already paying for Elastic Cloud
  • Your hosting provider offers managed Elasticsearch
  • You need Elastic's commercial features (APM, security, ML)

Choose OpenSearch if:

  • You're self-hosting (OpenSearch is free, no license restrictions)
  • You're on AWS (Amazon OpenSearch Service)
  • You want to avoid Elastic's license uncertainty

For most self-hosted Magento stores: OpenSearch. It's free, actively maintained, and Magento supports it natively since 2.4.6.

Installation (OpenSearch on Ubuntu)

# Add OpenSearch repo
curl -o- https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/opensearch-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/opensearch-keyring.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-2.x.list

apt-get update && apt-get install opensearch

# Set JVM heap (50% of available RAM, max 32GB)
echo "-Xms2g\n-Xmx2g" > /etc/opensearch/jvm.options.d/heap.options
systemctl enable opensearch && systemctl start opensearch
Enter fullscreen mode Exit fullscreen mode

Magento configuration

bin/magento config:set catalog/search/engine opensearch
bin/magento config:set catalog/search/opensearch_server_hostname localhost
bin/magento config:set catalog/search/opensearch_server_port 9200
bin/magento config:set catalog/search/opensearch_index_prefix magento2

bin/magento indexer:reindex catalogsearch_fulltext
bin/magento cache:flush
Enter fullscreen mode Exit fullscreen mode

Optimizing search performance

1. Only index searchable attributes

The more attributes you index, the larger your documents and the slower indexing becomes. In Admin → Stores → Attributes → Product, set "Use in Search" to "No" for:

  • Internal SKUs and supplier codes
  • Weight, dimensions (unless your customers search by these)
  • Internal status flags

2. Tune the number of shards

The default Magento index configuration creates 1 shard. For catalogs under 1M products, this is fine. For larger catalogs:

PUT /magento2_product_1/_settings
{
  "index": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  }
}
Enter fullscreen mode Exit fullscreen mode

3. Increase refresh interval during reindexing

By default, OpenSearch refreshes the index every second (making documents searchable). During full reindexing, increase this:

PUT /magento2_product_1/_settings
{
  "index.refresh_interval": "30s"
}
Enter fullscreen mode Exit fullscreen mode

Set it back to 1s after reindexing completes.

4. JVM heap tuning

The most common OpenSearch performance issue is heap pressure. Signs: slow queries, frequent GC pauses, OutOfMemoryError.

Rules:

  • Set heap to 50% of available RAM
  • Never exceed 32GB (above 32GB, JVM loses compressed oops efficiency)
  • Monitor heap usage: aim for < 75% under normal load
# Check current heap usage
curl localhost:9200/_cat/nodes?v&h=heap.percent,heap.current,heap.max
Enter fullscreen mode Exit fullscreen mode

Search relevance tuning

Default Magento search relevance is mediocre. Quick improvements:

Boost name and SKU matches:

Custom search query XML in your theme:

<referenceContainer name="catalogsearch.leftnav">
    <!-- Add field boosts -->
</referenceContainer>
Enter fullscreen mode Exit fullscreen mode

Or configure via Admin → Catalog → Catalog Search → Search Engine Optimization.

Enable "Did you mean" suggestions:

bin/magento config:set catalog/search/enable_eav_indexer 1
Enter fullscreen mode Exit fullscreen mode

Autocomplete with search suggestions:

Magento's built-in search autocomplete queries OpenSearch. Ensure your catalogsearch_fulltext indexer is up to date and consider a dedicated autocomplete index with only name/SKU fields for faster suggestions.

Monitoring OpenSearch health

# Cluster health
curl localhost:9200/_cluster/health?pretty

# Index stats
curl localhost:9200/magento2_product_1/_stats?pretty | jq '.indices[].total.search'

# Slow query log
curl -X PUT localhost:9200/magento2_product_1/_settings -H 'Content-Type: application/json' -d '{
  "index.search.slowlog.threshold.query.warn": "2s",
  "index.search.slowlog.threshold.fetch.warn": "500ms"
}'
Enter fullscreen mode Exit fullscreen mode

A healthy cluster shows status: green, with all shards assigned and no pending operations.

Common issues

Issue Cause Fix
status: red Unassigned shards Check disk space, node health
Slow reindexing Too many indexed attributes Disable unused attributes
Heap at 100% Undersized JVM heap Increase to 50% of RAM
Stale search results Indexer not running Check cron, run indexer:reindex
Connection refused OpenSearch not running systemctl status opensearch

Originally published on magevanta.com

Top comments (0)