@medusajs/index
Documentation | Website
Building blocks for digital commerce
Deprecated: the Index Module and
query.index()are deprecated and will be removed in a future release. Usequery.graph()instead, which filters across linked modules. See Filter by linked data models.
Index Module for Medusa: ingests data from multiple modules (by default products, variants, prices, and sales channels, plus linked models marked filterable) into a single Postgres-backed store so you can filter data by its linked records. Use it through Query's index method. It ships with @medusajs/medusa but is not registered by default, and the /store/products and /admin/products routes only use it when the index_engine feature flag is enabled.
At a glance
| Package | @medusajs/index |
| Type | Infrastructure Module |
| Module key | Modules.INDEX ("index") |
| Registered by default | No |
| Feature flag | index_engine (env MEDUSA_FF_INDEX_ENGINE), off by default |
Installation
No separate installation needed when you use @medusajs/medusa. Register the module, then run migrations:
import { defineConfig } from "@medusajs/framework/utils"
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/index-module",
},
],
})
npx medusa db:migrate
To make the core product API routes use the index, set MEDUSA_FF_INDEX_ENGINE=true. Data is ingested when the application starts. Keeping the index in sync with changes as they happen requires the Redis Event Module.
Usage
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
const query = container.resolve(ContainerRegistrationKeys.QUERY)
const { data: products } = await query.index({
entity: "product",
fields: ["id", "title", "sales_channels.id"],
filters: {
sales_channels: {
id: "sc_123",
},
},
})
Configuration
| Option | Type | Description | Default |
|---|---|---|---|
schema |
string |
GraphQL schema of the entities and fields to ingest. Replaces the default schema. | Product, ProductVariant, Price, and SalesChannel |