The production-ready Medusa DTC Starter is outRead the announcement
Elasticsearch logo

Elasticsearch

Elasticsearch search plugin for Medusa v2

npm install medusa-plugin-elasticsearch
Category
Regions
Worldwide
Version
1.1.2
Last updated
3 months ago
Monthly downloads
Loading downloads

Medusa Elasticsearch Plugin

NPM Version NPM Downloads Tests License Contributors Issues Share on X Share on Reddit

Elasticsearch search plugin for Medusa v2. Provides automatic product and category indexing, full-text search, and admin sync capabilities powered by Elasticsearch.

Features

  • Product and category indexing with real-time sync on create, update, and delete events
  • Full reindex via admin API endpoint or scheduled job (daily at midnight)
  • Batch syncing with pagination (50 items per batch) for large catalogs
  • Smart filtering -- only published products and active/non-internal categories are indexed
  • Custom document transformers per index type
  • Configurable Elasticsearch mappings, analyzers, and tokenizers
  • Search API for products () and categories ()
  • Admin API at with authentication
  • Admin UI settings page at with sync button and search testing
  • Workflow compensation -- automatic rollback on indexing failures
  • Built as a Medusa v2 module with workflows, subscribers, and scheduled jobs

Prerequisites


Installation

1. Install the plugin in your Medusa project:

2. Set environment variables in :

Or for a local Elasticsearch 9.x instance:

3. Register the plugin and module in :


Options

Module Options

NameDescriptionRequired
Elasticsearch client configuration (cloud, auth, node, etc.)true
Index configurations keyed by index name (, , or custom)false

Index Options (per index in )

NameDescriptionRequired
Custom document transformer functionfalse
Elasticsearch mapping configurationfalse
Elasticsearch index settings (analyzers, tokenizers, normalizers)false

API Endpoints

Store: Search Products

POST /store/products/search

Search products indexed in Elasticsearch. No authentication required.

Request body:

Store: Search Categories

POST /store/categories/search

Search product categories. No authentication required.

Request body:

Response: Standard Elasticsearch search response with .

Admin: Trigger Full Sync

POST /admin/elasticsearch/sync

Triggers a full reindex of all products and categories. Requires admin authentication (session, bearer, or API key).

Response:

The sync runs asynchronously, processing items in batches of 50.


Automatic Syncing

Real-time Events

The plugin automatically syncs on these events:

Products:

  • -- indexes the new product
  • -- re-indexes the updated product
  • -- removes the product from the index

Categories:

  • -- indexes the new category
  • -- re-indexes the updated category
  • -- removes the category from the index

Indexing Rules

  • Products: Only products are indexed. Draft/unpublished products are removed from the index.
  • Categories: Only and categories are indexed. Inactive or internal categories are removed.

Scheduled Reindex

A scheduled job runs daily at midnight to trigger a full reindex via the event.

Manual Reindex

Use the admin API endpoint or emit the event directly:


Workflows

The plugin exports workflows for direct use:


Custom Transformer

By default, products are indexed with a built-in transformer that flattens variant data, tags, categories, and collections. Categories are indexed with parent/children metadata. You can override either:


Architecture


Roadmap

Planned features for future releases:

  • i18n / multi-language support -- index per locale or field-suffix strategy for multilingual storefronts
  • Admin UI extension -- dashboard widget with sync button, index status, and document counts
  • Configurable reindex schedule -- allow custom cron expressions via module options
  • Collection indexing -- sync product collections alongside products and categories
  • Aggregation helpers -- pre-built faceted search support (price ranges, categories, tags)
  • Geo-search support -- location-based product search leveraging Elasticsearch's geo queries
  • Index aliasing -- zero-downtime reindexing using Elasticsearch index aliases
  • Bulk reindex CLI command -- one-time full reindex via Medusa CLI

Additional Resources


Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

MIT