• Модуль интеграций
  • Сообщество
  • Блог
Документация
Плагины и интеграцииВсе расширения для Medusa от сообществаСтартерыЗапускайте проекты быстрее с готовыми решениями
ЭкспертыПодберите специалиста для разработки и развития вашего проекта на MedusaКейсыПосмотрите примеры Medusa в продакшене и успешные внедрения
Представляем готовый к продакшену Medusa DTC Starter от Gorgo

26 августа 2026 г. · Продукт

Gorgo снижает затраты на адаптацию Medusa к локальным рынкам.

Мы разрабатываем плагины интеграции, осуществляем поддержку и развиваем сообщество разработчиков на Medusa в Telegram.

  • Ресурсы Medusa
  • Плагины и интеграции
  • Модуль интеграций
  • Стартеры
  • Эксперты
  • Кейсы
  • Medusa Чат в Telegram
  • Medusa Новости в Telegram
  • Документация Gorgo
  • Связаться с нами
  • TelegramGitHub
Плагины
E

Elasticsearch

Плагин поиска Elasticsearch для Medusa v2

npm install medusa-plugin-elasticsearch
Категория
Поиск
Создано
Peterborodatyy
Версия
1.1.2
Последнее обновление
1 неделю назад
Ежемесячные загрузки
Загрузка данных
Звезды на Github
8
npmNPMGitHubGithub

Medusa Elasticsearch Plugin

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

  • Medusa v2 application (v2.5.0+)
  • Elasticsearch 9.x instance or Elastic Cloud

Installation

1. Install the plugin in your Medusa project:

npm install medusa-plugin-elasticsearch

2. Set environment variables in :

1ELASTIC_CLOUD_ID=your_cloud_id
2ELASTIC_USER_NAME=your_username
3ELASTIC_PASSWORD=your_password

Or for a local Elasticsearch 9.x instance:

ELASTIC_NODE=http://localhost:9200

3. Register the plugin and module in :

1import { defineConfig } from "@medusajs/framework/utils"
2
3export default defineConfig({
4 // Register the plugin (loads subscribers, API routes, workflows, jobs)
5 plugins: [
6 {
7 resolve: "medusa-plugin-elasticsearch",
8 options: {},
9 },
10 ],
11 // Register the Elasticsearch module
12 modules: [
13 {
14 resolve: "medusa-plugin-elasticsearch/modules/elasticsearch",
15 options: {
16 config: {
17 // Option A: Elastic Cloud
18 cloud: {
19 id: process.env.ELASTIC_CLOUD_ID,
20 },
21 auth: {
22 username: process.env.ELASTIC_USER_NAME,
23 password: process.env.ELASTIC_PASSWORD,
24 },
25 // Option B: Local instance
26 // node: process.env.ELASTIC_NODE,
27 },
28 settings: {
29 products: {
30 // Optional: custom Elasticsearch mappings
31 mappings: {
32 properties: {
33 id: { type: "keyword" },
34 title: { type: "text" },
35 description: { type: "text" },
36 handle: { type: "keyword" },
37 },
38 },
39 // Optional: custom index settings (analyzers, tokenizers)
40 settings: {
41 analysis: {
42 tokenizer: {
43 autocomplete: {
44 type: "edge_ngram",
45 min_gram: 2,
46 max_gram: 10,
47 token_chars: ["letter", "digit"],
48 },
49 },
50 analyzer: {
51 autocomplete_index: {
52 type: "custom",
53 tokenizer: "autocomplete",
54 filter: ["lowercase"],
55 },
56 },
57 },
58 },
59 },
60 categories: {
61 mappings: {
62 properties: {
63 id: { type: "keyword" },
64 name: { type: "text" },
65 handle: { type: "keyword" },
66 description: { type: "text" },
67 },
68 },
69 },
70 },
71 },
72 },
73 ],
74})

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:

1{
2 "q": "sweatshirt",
3 "offset": 0,
4 "limit": 20,
5 "filter": {}
6}

Store: Search Categories

POST /store/categories/search

Search product categories. No authentication required.

Request body:

1{
2 "q": "electronics",
3 "offset": 0,
4 "limit": 20
5}

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:

1{
2 "message": "Syncing products to Elasticsearch"
3}

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:

1const eventBus = container.resolve("event_bus")
2await eventBus.emit({ name: "elasticsearch.sync", data: {} })

Workflows

The plugin exports workflows for direct use:

1import {
2 syncProductsToElasticsearchWorkflow,
3 deleteProductsFromElasticsearchWorkflow,
4 syncCategoriesToElasticsearchWorkflow,
5 deleteCategoriesFromElasticsearchWorkflow,
6} from "medusa-plugin-elasticsearch/workflows"
7
8// Sync specific products
9await syncProductsToElasticsearchWorkflow(container).run({
10 input: { ids: ["prod_01ABC"] },
11})
12
13// Sync specific categories
14await syncCategoriesToElasticsearchWorkflow(container).run({
15 input: { ids: ["pcat_01ABC"] },
16})
17
18// Delete from index
19await deleteProductsFromElasticsearchWorkflow(container).run({
20 input: { ids: ["prod_01ABC"] },
21})
22
23await deleteCategoriesFromElasticsearchWorkflow(container).run({
24 input: { ids: ["pcat_01ABC"] },
25})

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:

1{
2 settings: {
3 products: {
4 transformer: (product) => ({
5 id: product.id,
6 title: product.title,
7 description: product.description,
8 handle: product.handle,
9 thumbnail: product.thumbnail,
10 }),
11 },
12 categories: {
13 transformer: (category) => ({
14 id: category.id,
15 name: category.name,
16 handle: category.handle,
17 }),
18 },
19 },
20}

Architecture

1src/
2 admin/ # Admin UI extension
3 lib/sdk.ts # Medusa JS SDK client
4 routes/settings/elasticsearch/
5 page.tsx # Settings page (sync + search testing)
6 modules/elasticsearch/ # Elasticsearch module
7 index.ts # Module definition (Module())
8 service.ts # ES client service
9 types.ts # Type definitions
10 loaders/initialize.ts # Index initialization on startup
11 subscribers/
12 product-upsert.ts # Sync on product.created / product.updated
13 product-deleted.ts # Remove on product.deleted
14 category-upsert.ts # Sync on product-category.created / updated
15 category-deleted.ts # Remove on product-category.deleted
16 elasticsearch-sync.ts # Full reindex (products + categories)
17 workflows/
18 sync-products-to-elasticsearch.ts # Fetch + index products
19 delete-products-from-elasticsearch.ts # Delete products from index
20 sync-categories-to-elasticsearch.ts # Fetch + index categories
21 delete-categories-from-elasticsearch.ts # Delete categories from index
22 index.ts # Workflow exports
23 api/
24 middlewares.ts # Validation + admin auth
25 store/products/search/ # POST /store/products/search
26 store/categories/search/ # POST /store/categories/search
27 admin/elasticsearch/sync/ # POST /admin/elasticsearch/sync
28 jobs/
29 elasticsearch-reindex.ts # Daily scheduled reindex
30 utils/
31 transformer.ts # Default product + category transformers
32 types/
33 index.ts # Public type exports

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

  • Medusa v2 Documentation
  • Medusa Plugin Guide
  • Elasticsearch Node.js Client v9
  • Elasticsearch Reference

Contributing

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

License

MIT

Еще в этой категории

Посмотреть все
Поиск
MeiliSearch logo

MeiliSearch

От Rokmohar

Open-source поисковый движок для вашей витрины

Загрузка данных
GitHubnpm
Поиск
MeiliSearch logo

MeiliSearch

От Vymalo

Подключите быстрый поиск с MeiliSearch

Загрузка данных
GitHubnpm
Поиск
Relewise logo

Relewise

От Relewise

Прокачайте поиск по товарам с Relewise

Загрузка данных
npm