This example demonstrates how to integrate Meilisearch with Medusa for product search functionality.
- Product Indexing: Automatically sync products to Meilisearch when they are created or updated
- Product Deletion: Remove products from Meilisearch when they are deleted
- Search API: Store API endpoint for searching products using Meilisearch
- Admin Interface: Admin panel to manually trigger data sync
- Event-driven Sync: Automatic synchronization based on product events
yarn installAdd the following environment variables to your .env file:
MEILISEARCH_HOST=http://localhost:7700
MEILISEARCH_API_KEY=your_meilisearch_api_key
MEILISEARCH_PRODUCT_INDEX_NAME=productsMake sure you have Meilisearch running locally or have access to a Meilisearch instance.
# Using Docker
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest
# Or install locally
curl -L https://install.meilisearch.com | sh
./meilisearchyarn devProducts are automatically synced to Meilisearch when:
- A product is created
- A product is updated
- A product is deleted
You can manually trigger a full sync from the admin panel:
- Go to Settings → Meilisearch
- Click "Sync Data to Meilisearch"
Use the search endpoint to query products:
POST /store/products/search
Content-Type: application/json
{
"query": "your search query"
}- Module:
src/modules/meilisearch/- Core Meilisearch integration - Workflows:
src/workflows/- Business logic for syncing and deleting products - Subscribers:
src/subscribers/- Event handlers for product changes - API Routes:
src/api/- REST endpoints for search and admin operations - Admin Interface:
src/admin/- Admin panel for managing the integration
- MeilisearchModuleService: Handles all Meilisearch operations
- syncProductsWorkflow: Syncs products to Meilisearch
- deleteProductsFromMeilisearchWorkflow: Removes products from Meilisearch
- Event Subscribers: Listen for product events and trigger appropriate workflows
The integration is configured in medusa-config.ts:
modules: [
{
resolve: "./src/modules/meilisearch",
options: {
host: process.env.MEILISEARCH_HOST!,
apiKey: process.env.MEILISEARCH_API_KEY!,
productIndexName: process.env.MEILISEARCH_PRODUCT_INDEX_NAME!,
}
}
]Run the integration tests:
yarn test:integration:http
yarn test:integration:modules
yarn test:unit