1 {"slug":"/references/search/service","title":"How to Use Search Module","frontmatter":{"slug":"/references/search/service","tags":["search","server","how to"],"sidebar_label":"Use Search Module"},"toc":[{"title":"Resolve Search Module's Service","id":"resolve-search-module-s-service","level":2},{"title":"createIndexMigrationPlan","id":"createindexmigrationplan","level":2},{"title":"Example","id":"example","level":3},{"title":"Returns","id":"createindexmigrationplan-returns","level":3},{"title":"deleteDocuments","id":"deletedocuments","level":2},{"title":"Example","id":"example-1","level":3},{"title":"Parameters","id":"deletedocuments-parameters","level":3},{"title":"Returns","id":"deletedocuments-returns","level":3},{"title":"deleteIndex","id":"deleteindex","level":2},{"title":"Example","id":"example-2","level":3},{"title":"Parameters","id":"deleteindex-parameters","level":3},{"title":"Returns","id":"deleteindex-returns","level":3},{"title":"executeIndexMigrationPlan","id":"executeindexmigrationplan","level":2},{"title":"Example","id":"example-3","level":3},{"title":"Parameters","id":"executeindexmigrationplan-parameters","level":3},{"title":"Returns","id":"executeindexmigrationplan-returns","level":3},{"title":"getIndex","id":"getindex","level":2},{"title":"Example","id":"example-4","level":3},{"title":"Parameters","id":"getindex-parameters","level":3},{"title":"Returns","id":"getindex-returns","level":3},{"title":"ingest","id":"ingest","level":2},{"title":"Example","id":"example-5","level":3},{"title":"Parameters","id":"ingest-parameters","level":3},{"title":"Returns","id":"ingest-returns","level":3},{"title":"listIndexes","id":"listindexes","level":2},{"title":"Example","id":"example-6","level":3},{"title":"Returns","id":"listindexes-returns","level":3},{"title":"listRetrievableFields","id":"listretrievablefields","level":2},{"title":"Example","id":"example-7","level":3},{"title":"Parameters","id":"listretrievablefields-parameters","level":3},{"title":"Returns","id":"listretrievablefields-returns","level":3},{"title":"reindex","id":"reindex","level":2},{"title":"Example","id":"example-8","level":3},{"title":"Parameters","id":"reindex-parameters","level":3},{"title":"Returns","id":"reindex-returns","level":3},{"title":"search","id":"search","level":2},{"title":"Example","id":"example-9","level":3},{"title":"Type Parameters","id":"search-type-parameters","level":3},{"title":"Parameters","id":"search-parameters","level":3},{"title":"Returns","id":"search-returns","level":3},{"title":"searchMany","id":"searchmany","level":2},{"title":"Example","id":"example-10","level":3},{"title":"Parameters","id":"searchmany-parameters","level":3},{"title":"Returns","id":"searchmany-returns","level":3},{"title":"upsertDocuments","id":"upsertdocuments","level":2},{"title":"Example","id":"example-11","level":3},{"title":"Parameters","id":"upsertdocuments-parameters","level":3},{"title":"Returns","id":"upsertdocuments-returns","level":3}],"blocks":[{"kind":"markdown","html":"In this document, you’ll learn about the different methods in the Search Module's service and how to use them."},{"kind":"note","variant":"note","html":"The Search Module is available starting [Medusa v2.21.1](https://github.com/medusajs/medusa/releases/tag/v2.21.1)."},{"kind":"markdown","html":"---"},{"kind":"heading","level":2,"text":"Resolve Search Module's Service","id":"resolve-search-module-s-service"},{"kind":"markdown","html":"In your workflow's step, you can resolve the Search Module's service from the Medusa container:\n\n```ts\nimport { Modules } from \"@medusajs/framework/utils\"\nimport { createStep } from \"@medusajs/framework/workflows-sdk\"\n\nconst step1 = createStep(\n \"step-1\",\n async ({}, { container }) => {\n const searchModuleService = container.resolve(\n Modules.Search\n )\n \n // TODO use searchModuleService\n } \n)\n```\n\nYou can then use the Search Module's service's methods in the step, which would use the underlying provider's logic. The rest of this guide details these methods.\n\n---"},{"kind":"heading","level":2,"text":"createIndexMigrationPlan","id":"createindexmigrationplan"},{"kind":"markdown","html":"This method plans what it would take to bring the physical indexes in line\nwith the loaded index definitions. Planning is separate from executing it. It's\nuseful for printing the actions, or executing them later with [executeIndexMigrationPlan](/references/search/service#executeindexmigrationplan)."},{"kind":"heading","level":3,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nconst actions = await searchModuleService.createIndexMigrationPlan()\n```"},{"kind":"heading","level":3,"text":"Returns","id":"createindexmigrationplan-returns"},{"kind":"typeList","sectionTitle":"createIndexMigrationPlan","types":[{"name":"Promise","type":"Promise&#60;[SearchIndexMigrationAction](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexMigrationAction)[]&#62;","optional":false,"defaultValue":"","description":"The actions required to\nbring the physical indexes in line with the definitions. Indexes that are\nalready up to date are returned as `noop` actions, and indexes without a definition\nare returned as a `drop`, which will delete all data around them.\n[executeIndexMigrationPlan](/references/search/service#executeindexmigrationplan).","expandable":false,"children":[{"name":"SearchIndexMigrationAction[]","type":"[SearchIndexMigrationAction](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexMigrationAction)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"action","type":"`\"create\"`","description":"No version of this index has ever gone live. A new version is built,\nto be filled and made active at application start.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"`string`","description":"The name of the index to create.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"physical_name","type":"`string`","description":"The physical index the new version is built under.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"definition_hash","type":"`string`","description":"A hash of the definition the version is created from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"version","type":"`number`","description":"The new version's number.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"active_physical_name","type":"`string`","description":"The physical index of the version currently serving reads.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"active_definition_hash","type":"`string`","description":"A hash of the definition the active version was built from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The provider the new version is built on.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"previous_provider","type":"`string`","description":"The provider that holds the version currently serving reads. Set only\nwhen it differs from `provider`, so a later migration knows to clean up\nthe previous engine's data once this version becomes active.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"physical_names","type":"`string`[]","description":"Every physical index removed along with it, newest version first.\nEmpty when a record was created but no version was ever built.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":2,"text":"deleteDocuments","id":"deletedocuments"},{"kind":"markdown","html":"This method removes every document in an index matching the specified filters.\n\nDeleting by ID isn't a special case: it's a filter on the index's primary\nkey, such as `{ id: [\"prod_1\"] }`."},{"kind":"heading","level":3,"text":"Example","id":"example-1"},{"kind":"markdown","html":"To delete documents by ID:\n\n```ts\nconst task = await searchModuleService.deleteDocuments({\n index: \"product\",\n filters: {\n id: [\"prod_123\", \"prod_456\"],\n },\n})\n```\n\nTo delete every document matching a filter:\n\n```ts\nconst task = await searchModuleService.deleteDocuments({\n index: \"product\",\n filters: {\n status: \"draft\",\n },\n})\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"deletedocuments-parameters"},{"kind":"typeList","sectionTitle":"deleteDocuments","types":[{"name":"input","type":"`object`","description":"The documents to remove.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"index","type":"`string`","description":"The name of the index to delete from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"The filters selecting the documents to\nremove. At least one filter is required.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"deletedocuments-returns"},{"kind":"typeList","sectionTitle":"deleteDocuments","types":[{"name":"Promise","type":"Promise&#60;[SearchTask](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchTask)&#62;","optional":false,"defaultValue":"","description":"The write's task.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID identifying the write in the search engine, which is passed back to\nthe provider's `waitForTask` method. It's set only for a deferred write,\nsince a provider applying writes inline has nothing to identify.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"`string`","description":"The name of the index the write was applied to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[SearchTaskStatus](/references/types/SearchTypes/types/types.SearchTypes.SearchTaskStatus)","description":"The write's status.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"error","type":"`object`","description":"The error that made the write fail, if its `status` is `failed`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"message","type":"`string`","description":"The error's message.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"The error's code, as reported by the search engine.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":2,"text":"deleteIndex","id":"deleteindex"},{"kind":"markdown","html":"This method deletes an index: every physical index ever built for it is dropped\nfrom its search engine, along with the versions and sync history behind them.\n\nNothing is left for the next migration to find, so it rebuilds the index from\nscratch starting at version 1. Use it to recover from an index whose physical\nstate has drifted past what a reindex can repair.\n\nThe index definition itself is untouched — it lives in your code, not in the\ndatabase."},{"kind":"heading","level":3,"text":"Example","id":"example-2"},{"kind":"markdown","html":"```ts\nconst { deleted_versions } = await searchModuleService.deleteIndex(\"product\")\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"deleteindex-parameters"},{"kind":"typeList","sectionTitle":"deleteIndex","types":[{"name":"index","type":"`string`","description":"The name of the index to delete.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"Returns","id":"deleteindex-returns"},{"kind":"typeList","sectionTitle":"deleteIndex","types":[{"name":"Promise","type":"Promise&#60;[SearchIndexDeleteResult](/references/search/interfaces/search.SearchIndexDeleteResult)&#62;","optional":false,"defaultValue":"","description":"The deleted index and how many of\nits versions were dropped.","expandable":false,"children":[{"name":"index","type":"`string`","description":"The name of the index that was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_versions","type":"`number`","description":"How many of the index's versions were dropped. `0` when the index is\nregistered but was never migrated, so nothing was ever built for it.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"executeIndexMigrationPlan","id":"executeindexmigrationplan"},{"kind":"markdown","html":"This method executes a migration plan, creating, altering and dropping\nphysical indexes. Every action is idempotent, so executing the same plan\ntwice is a no-op.\n\nThe indexes this method creates are filled by the seed that runs at\napplication start, so an index it creates serves nothing until then."},{"kind":"heading","level":3,"text":"Example","id":"example-3"},{"kind":"markdown","html":"```ts\nconst actions = await searchModuleService.createIndexMigrationPlan()\nawait searchModuleService.executeIndexMigrationPlan(actions)\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"executeindexmigrationplan-parameters"},{"kind":"typeList","sectionTitle":"executeIndexMigrationPlan","types":[{"name":"actions","type":"[SearchIndexMigrationAction](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexMigrationAction)[]","description":"The actions to execute, as\nreturned by [createIndexMigrationPlan](/references/search/service#createindexmigrationplan).","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"action","type":"`\"create\"`","description":"No version of this index has ever gone live. A new version is built,\nto be filled and made active at application start.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"`string`","description":"The name of the index to create.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"physical_name","type":"`string`","description":"The physical index the new version is built under.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"definition_hash","type":"`string`","description":"A hash of the definition the version is created from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"version","type":"`number`","description":"The new version's number.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"active_physical_name","type":"`string`","description":"The physical index of the version currently serving reads.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"active_definition_hash","type":"`string`","description":"A hash of the definition the active version was built from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The provider the new version is built on.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"previous_provider","type":"`string`","description":"The provider that holds the version currently serving reads. Set only\nwhen it differs from `provider`, so a later migration knows to clean up\nthe previous engine's data once this version becomes active.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"physical_names","type":"`string`[]","description":"Every physical index removed along with it, newest version first.\nEmpty when a record was created but no version was ever built.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"executeindexmigrationplan-returns"},{"kind":"typeList","sectionTitle":"executeIndexMigrationPlan","types":[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"Resolves when the physical indexes are created and\naltered.","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"getIndex","id":"getindex"},{"kind":"markdown","html":"This method retrieves an index's definition with the module's defaults\napplied: the provider it resolved to, the root physical index name its\nversions are derived from, and the `primary_key` its documents are keyed\nby, which is what a hit's `id` holds."},{"kind":"heading","level":3,"text":"Example","id":"example-4"},{"kind":"markdown","html":"```ts\nconst definition = searchModuleService.getIndex(\"product\")\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"getindex-parameters"},{"kind":"typeList","sectionTitle":"getIndex","types":[{"name":"index","type":"`string`","description":"The name of the index.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"Returns","id":"getindex-returns"},{"kind":"typeList","sectionTitle":"getIndex","types":[{"name":"name","type":"`string`","description":"The index's unique name, which is what `query.search({ entity })` resolves\nagainst.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint used to hydrate non-indexed fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields the index holds, keyed by their path in the document.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"[SearchFieldKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFieldKind)","description":"The field's type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"array","type":"`boolean`","description":"Whether the field holds an array of the declared `type`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"searchable","type":"`boolean` \\| `object`","description":"Whether the field is matched against a free-text query, optionally with a\n`weight` boosting its relevance. The weight is applied at build time on some\nengines, such as Meilisearch and Algolia, and at query time on others, such\nas Typesense and Elasticsearch.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"weight","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"filterable","type":"`boolean`","description":"Whether the field can be used in a query's filters.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sortable","type":"`boolean`","description":"Whether results can be sorted by the field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facetable","type":"`boolean` \\| `object`","description":"Whether the field can be faceted, and which facet types it supports.\nDefaults to `[\"value\"]`, or `[\"range\"]` for numeric and date fields.\n`\"stats\"` is opt-in, since implying it would make numeric fields unusable on\nproviders without aggregations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"types","type":"[SearchFacetKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFacetKind)[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"retrievable","type":"`boolean`","description":"Whether the field comes back on hits. `false` for index-only fields, such as a\nblob used purely for matching. `query.search` reads this to decide which\nrequested fields the engine can serve and which need `query.graph`.\n\nVector fields default to not retrievable — embeddings are not useful on\nhits. Set `retrievable: true`, or `.retrievable()` in the DSL, to return\nthem.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields of a nested object, only used when `type` is `object`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"[SearchFieldKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFieldKind)","description":"The field's type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"array","type":"`boolean`","description":"Whether the field holds an array of the declared `type`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"searchable","type":"`boolean` \\| `object`","description":"Whether the field is matched against a free-text query, optionally with a\n`weight` boosting its relevance. The weight is applied at build time on some\nengines, such as Meilisearch and Algolia, and at query time on others, such\nas Typesense and Elasticsearch.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filterable","type":"`boolean`","description":"Whether the field can be used in a query's filters.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sortable","type":"`boolean`","description":"Whether results can be sorted by the field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facetable","type":"`boolean` \\| `object`","description":"Whether the field can be faceted, and which facet types it supports.\nDefaults to `[\"value\"]`, or `[\"range\"]` for numeric and date fields.\n`\"stats\"` is opt-in, since implying it would make numeric fields unusable on\nproviders without aggregations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"retrievable","type":"`boolean`","description":"Whether the field comes back on hits. `false` for index-only fields, such as a\nblob used purely for matching. `query.search` reads this to decide which\nrequested fields the engine can serve and which need `query.graph`.\n\nVector fields default to not retrievable — embeddings are not useful on\nhits. Set `retrievable: true`, or `.retrievable()` in the DSL, to return\nthem.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields of a nested object, only used when `type` is `object`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"dimensions","type":"`number`","description":"The dimensionality of the embedding stored in a `type: \"vector\"` field.\nRequired for vector fields; meaningless on any other type. When `embed` is\nomitted, every vector written to the field must have exactly this many\ncomponents.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"embed","type":"`boolean`","description":"When `true` on a vector field, documents pass a string and the engine\nembeds it at write time, and for `search_options.vector.query` at query\ntime. Omit `embed` to supply embeddings yourself as a `number[]`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Field options specific to a search engine, keyed by provider identifier, such\nas `{ meilisearch: { ... } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"dimensions","type":"`number`","description":"The dimensionality of the embedding stored in a `type: \"vector\"` field.\nRequired for vector fields; meaningless on any other type. When `embed` is\nomitted, every vector written to the field must have exactly this many\ncomponents.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"embed","type":"`boolean`","description":"When `true` on a vector field, documents pass a string and the engine\nembeds it at write time, and for `search_options.vector.query` at query\ntime. Omit `embed` to supply embeddings yourself as a `number[]`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Field options specific to a search engine, keyed by provider identifier, such\nas `{ meilisearch: { ... } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"events","type":"`string`[]","description":"Events related and that can affect the data for this index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"consume","type":"(`event`: [Event](/references/types/EventBusTypes/types/types.EventBusTypes.Event)&#60;any&#62;, `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => Promise&#60;[SearchMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchMutation)[]&#62;","description":"Executed on event ingestion to determine the action that needs to be performed on the index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"seed","type":"(`context`: [SearchSeedContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchSeedContext)) => AsyncIterable&#60;[SearchMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchMutation)[]&#62;","description":"Yields mutations in batches — the same shape `consume` returns, so a\nseed can express a delete, not just an upsert. Ran when there is no data\nin the index, on reindex, and for the catch-up pass after a full seed.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"primary_key","type":"`string`","description":"The field whose value keys the index's documents.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The identifier of the provider backing this index.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"settings","type":"[SearchIndexSettings](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexSettings)","description":"The settings applied to the index.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"typo_tolerance","type":"`object`","description":"How misspelled terms are matched.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"enabled","type":"`boolean`","description":"Whether typo tolerance is enabled at all.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_word_size_for_one_typo","type":"`number`","description":"The shortest term length that tolerates a single typo. A provider with a\nhigher floor of its own rejects a shorter length from `upsertIndex`; one\nthat doesn't match by edit distance at all ignores this.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_word_size_for_two_typos","type":"`number`","description":"The shortest term length that tolerates two typos. Cannot be lower than\n`min_word_size_for_one_typo`. Ignored by a provider that doesn't match by\nedit distance.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disabled_on_attributes","type":"`string`[]","description":"The dotted paths of the fields that must always match exactly, such as a\nSKU or a handle. A provider that can't exclude a single field rejects\nthis rather than fuzzy-matching it anyway.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"distinct_attribute","type":"`string`","description":"The dotted path of a field that hits are deduplicated by, returning at most\none hit per distinct value. Overridden per query by `search_options.distinct`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Index settings specific to a search engine, keyed by provider identifier.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"definition_hash","type":"`string`","description":"A hash of the definition, which the module compares to detect that an index\ndrifted from its definition and must be migrated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"physical_name","type":"`string`","description":"The root physical index name, derived from `name` and the module's\n`index_prefix`. Never queried directly: each version of this index gets its\nown physical index derived from this root, and the module resolves which\none is currently active before reading or writing.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"ingest","id":"ingest"},{"kind":"markdown","html":"This method applies an event to every index that declared it in its\ndefinition's `events`, using each index's `consume` function to turn the\nevent into document writes or deletions.\n\nThe Search Module subscribes to the declared events and calls this method for\nyou. You only need to call it directly to replay an event, or to ingest an\nevent that wasn't emitted through the Event Bus Module.\n\nThe returned promise resolves once the search engine has accepted the\nwrites. Failures are thrown, leaving redelivery to the event bus."},{"kind":"heading","level":3,"text":"Example","id":"example-5"},{"kind":"markdown","html":"```ts\nconst tasks = await searchModuleService.ingest({\n name: \"product.updated\",\n data: {\n id: \"prod_123\",\n },\n})\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"ingest-parameters"},{"kind":"typeList","sectionTitle":"ingest","types":[{"name":"event","type":"[Event](/references/medusa/types/medusa.Event)&#60;any&#62;","description":"The event to apply.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"The event's name.","optional":false,"defaultValue":"","example":"user.created","expandable":false,"children":[]},{"name":"metadata","type":"[EventMetadata](/references/medusa/types/medusa.EventMetadata)","description":"Additional meadata to pass with the event.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"eventGroupId","type":"`string`","description":"The ID of the event's group. Grouped events are useful when you have distributed transactions\nwhere you need to explicitly group, release and clear events upon lifecycle events of a transaction.\n\nWhen set, you must release the grouped events using the Event Module's `releaseGroupedEvents` method to emit the events.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date the event was emitted.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"published_at","type":"`Date`","description":"The date the event was published to the event bus. If it's a grouped event, this will be the date the group was released.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"data","type":"TData","description":"The data payload that subscribers receive. For example, the ID or IDs of the created user. (e.g. &#123; id: \"123\" &#125; or &#123; ids: [\"123\", \"456\"] &#125;)","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"ingest-returns"},{"kind":"typeList","sectionTitle":"ingest","types":[{"name":"Promise","type":"Promise&#60;[SearchTask](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchTask)[]&#62;","optional":false,"defaultValue":"","description":"One task per write. An event that no index\ndeclared resolves to an empty array.","expandable":false,"children":[{"name":"SearchTask[]","type":"[SearchTask](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchTask)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID identifying the write in the search engine, which is passed back to\nthe provider's `waitForTask` method. It's set only for a deferred write,\nsince a provider applying writes inline has nothing to identify.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"`string`","description":"The name of the index the write was applied to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[SearchTaskStatus](/references/types/SearchTypes/types/types.SearchTypes.SearchTaskStatus)","description":"The write's status.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"error","type":"`object`","description":"The error that made the write fail, if its `status` is `failed`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"message","type":"`string`","description":"The error's message.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"The error's code, as reported by the search engine.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]}]},{"kind":"heading","level":2,"text":"listIndexes","id":"listindexes"},{"kind":"markdown","html":"This method retrieves the registered indexes, their status, and the leaf\nfields each of them stores. Definitions that haven't been migrated yet are\nincluded with a `pending` status."},{"kind":"heading","level":3,"text":"Example","id":"example-6"},{"kind":"markdown","html":"```ts\nconst indexes = await searchModuleService.listIndexes()\n```"},{"kind":"heading","level":3,"text":"Returns","id":"listindexes-returns"},{"kind":"typeList","sectionTitle":"listIndexes","types":[{"name":"Promise","type":"Promise&#60;[SearchIndexDetails](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexDetails)[]&#62;","optional":false,"defaultValue":"","description":"The registered indexes.","expandable":false,"children":[{"name":"SearchIndexDetails[]","type":"[SearchIndexDetails](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexDetails)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"Unique index name, as used in `query.search({ entity })`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint used to hydrate non-indexed fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"Identifier of the provider backing this index.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[SearchIndexStatus](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexStatus)","description":"Lifecycle status of the index.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"[SearchIndexFieldInfo](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexFieldInfo)[]","description":"Leaf fields stored in the index.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"Dotted path of the field in the index, e.g. `title` or `variants.sku`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[SearchFieldKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFieldKind)","description":"The field's index type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"searchable","type":"`boolean`","description":"Whether the field is used for free-text matching.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"filterable","type":"`boolean`","description":"Whether the field can be used in filters.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sortable","type":"`boolean`","description":"Whether results can be sorted by this field.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"facetable","type":"`boolean`","description":"Whether the field can be faceted.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]}]},{"kind":"heading","level":2,"text":"listRetrievableFields","id":"listretrievablefields"},{"kind":"markdown","html":"This method retrieves the field paths an index can return. `query.search`\nuses it to split the fields a caller asked for between the search engine and\n`query.graph`."},{"kind":"heading","level":3,"text":"Example","id":"example-7"},{"kind":"markdown","html":"```ts\nconst fields = searchModuleService.listRetrievableFields(\"product\")\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"listretrievablefields-parameters"},{"kind":"typeList","sectionTitle":"listRetrievableFields","types":[{"name":"index","type":"`string`","description":"The name of the index.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"Returns","id":"listretrievablefields-returns"},{"kind":"typeList","sectionTitle":"listRetrievableFields","types":[{"name":"string[]","type":"`string`[]","optional":false,"defaultValue":"","description":"The retrievable field paths, such as `title` or\n`variants.sku`.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"reindex","id":"reindex"},{"kind":"markdown","html":"This method triggers a background job that rebuilds one or more indexes from\ntheir definitions' `seed` functions. Medusa handles reindexing automatically, as explained\nin the [Reindexing and Migrations Guide](https://docs.medusajs.com/resources/infrastructure-modules/search/reindexing).\nThis method is useful to trigger the reindex manually after changing what a `seed`\nproduces, or to recover an index whose documents drifted from their source\nof truth.\n\nThe job is started, not awaited: the returned result only tells you which\nindexes are being rebuilt."},{"kind":"heading","level":3,"text":"Example","id":"example-8"},{"kind":"markdown","html":"To rebuild a single index:\n\n```ts\nconst { job_id } = await searchModuleService.reindex({\n index: \"product\",\n})\n```\n\nTo rebuild part of an index in place:\n\n```ts\nconst { job_id } = await searchModuleService.reindex({\n index: \"product\",\n strategy: \"in_place\",\n filters: {\n collection_id: \"pcol_123\",\n },\n})\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"reindex-parameters"},{"kind":"typeList","sectionTitle":"reindex","types":[{"name":"input","type":"[SearchReindexInput](/references/search/interfaces/search.SearchReindexInput)","description":"The reindex options, such as which\nindexes to rebuild and what strategy to use. If not provided, every index is\nrebuilt with the `swap` strategy.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"index","type":"`string` \\| `string`[]","description":"The name of the index, or the names of the indexes, to rebuild. If not\nprovided, every registered index is rebuilt.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"strategy","type":"[SearchReindexStrategy](/references/search/types/search.SearchReindexStrategy)","description":"The strategy to rebuild the index with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"`Record<string, unknown>`","description":"Filters passed to the index definition's `seed` function to rebuild only a\nsubset of the index's documents.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"since","type":"`Date`","description":"Rebuilds only documents that changed at or after this date, passed to the\nindex definition's `seed` function. Like `filters`,\nthis always runs in place — a version built from a subset was never\nmeant to serve every read, so it never swaps in.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"reindex-returns"},{"kind":"typeList","sectionTitle":"reindex","types":[{"name":"Promise","type":"Promise&#60;[SearchReindexResult](/references/search/interfaces/search.SearchReindexResult)&#62;","optional":false,"defaultValue":"","description":"The ID of the job performing the\nreindex, and the indexes it rebuilds.","expandable":false,"children":[{"name":"job_id","type":"`string`","description":"The ID of the background job performing the reindex.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"indexes","type":"`string`[]","description":"The names of the indexes being rebuilt.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"search","id":"search"},{"kind":"markdown","html":"This method searches an index for documents matching the given query. The\nSearch Module resolves the index's provider and delegates the query to it.\n\nThe free-text query is passed as `q` among the `filters`."},{"kind":"heading","level":3,"text":"Example","id":"example-9"},{"kind":"markdown","html":"A simple example that searches an index for a free-text query:\n\n```ts\nconst result = await searchModuleService.search({\n entity: \"product\",\n filters: {\n q: \"shirt\",\n },\n})\n```\n\nTo filter, paginate, sort, and retrieve facets:\n\n```ts\nconst result = await searchModuleService.search({\n entity: \"product\",\n fields: [\"id\", \"title\", \"variants.sku\"],\n filters: {\n q: \"shirt\",\n status: \"published\",\n \"variants.price\": { $lte: 5000 },\n },\n pagination: {\n skip: 0,\n take: 20,\n order: { _score: \"DESC\" },\n },\n search_options: {\n facets: [\"type_id\"],\n },\n})\n```"},{"kind":"heading","level":3,"text":"Type Parameters","id":"search-type-parameters"},{"kind":"typeList","sectionTitle":"search","types":[{"name":"T","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"Parameters","id":"search-parameters"},{"kind":"typeList","sectionTitle":"search","types":[{"name":"query","type":"[SearchQuery](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchQuery)","description":"The query to run against the search index.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"entity","type":"TEntry","description":"The name of the index to query, which defaults to the index whose name\nequals the entity.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"The dotted paths of the fields the search engine should return. Only fields\navailable in the search engine can be passed here.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"The filters to apply, including the free-text query as `q`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"pagination","type":"[SearchPagination](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchPagination)","description":"How the results are paginated and sorted.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"skip","type":"`number`","description":"The number of documents to skip before the returned hits. Mutually exclusive\nwith `cursor`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"take","type":"`number`","description":"The maximum number of hits to return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`Record<string, [SearchOrderBy](/references/types/SearchTypes/types/types.SearchTypes.SearchOrderBy)>`","description":"The fields to sort the hits by, keyed by the field's dotted path. The\nreserved `_score` key sorts by relevance.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cursor","type":"`string`","description":"An opaque provider cursor, as returned in a previous result's\n`metadata.next_cursor`. Mutually exclusive with `skip`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"search_options","type":"[SearchOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchOptions)","description":"The options changing how the query is matched, scored, and aggregated.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"attributes_to_search_on","type":"`string`[]","description":"The dotted paths of the fields to match the free-text query against. Defaults\nto every field marked `searchable` on the index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"match_strategy","type":"[SearchMatchStrategy](/references/types/SearchTypes/types/types.SearchTypes.SearchMatchStrategy)","description":"How query terms combine.\n\n- `\"all\"` (default): every term must appear as a complete token.\n- `\"any\"`: at least one term must match.\n- `\"last\"`: typeahead. Completed terms must match in full; the last term\n is a prefix, so `\"my sear\"` matches `\"My search results\"`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"typo_tolerance","type":"`boolean`","description":"Whether to match terms that are misspelled by a character or two.\nit is ignored unless the query includes a free-text `q` and the\nsearched fields have typo tolerance enabled in the index's `settings.typo_tolerance`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facets","type":"(`string` \\| [SearchFacetRequest](/references/types/SearchTypes/types/types.SearchTypes.SearchFacetRequest))[]","description":"The facets to compute alongside the hits. A string is shorthand for a `value`\nfacet on that field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disjunctive_facets","type":"`boolean`","description":"Compute each facet ignoring the filter on that same field, so a storefront\nkeeps showing sibling values of an active filter. Needs one query per facet\non every engine reviewed, so the module expands them and hands the set to\n`provider.searchMany`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"highlight","type":"`boolean` \\| [SearchHighlightOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchHighlightOptions)","description":"How the matched terms are highlighted in the returned hits. Applied only\nwhen the query includes a free-text `q`; otherwise it is ignored.\n\n`true` highlights every field the query searches on. Pass an object to pick\nfields, tags, or snippet cropping.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"distinct","type":"`string`","description":"Return at most one hit per distinct value of this field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_score","type":"`number`","description":"Discard hits scoring below this threshold.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_score","type":"`boolean`","description":"Whether to return each hit's relevance score.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locales","type":"`string`[]","description":"Query-time language hint, e.g. `[\"en\"]`. Engines that analyze per language\n(Meilisearch, Algolia) use it to pick the analyzer; a provider that cannot\nhonour it rejects it rather than silently matching differently. Neither\nfirst-party provider does: configure the analyzer language on the provider\n(postgres) or on the field (Medusa) instead.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"vector","type":"[SearchVectorOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchVectorOptions)","description":"The options of a vector, or semantic, search to run instead of, or alongside,\nthe free-text query.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"[SearchCountStrategy](/references/types/SearchTypes/types/types.SearchTypes.SearchCountStrategy)","description":"How the total number of matching documents is computed. `\"exact\"` may be\nrejected or slow depending on the provider.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Escape hatch for engine features the interface does not model, keyed by\nprovider identifier, e.g. `{ typesense: { drop_tokens_threshold: 0 } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"context","type":"[QueryContextType](/references/types/CommonTypes/types/types.CommonTypes.QueryContextType)","description":"The context passed to the `query.graph` call during hydration.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"search-returns"},{"kind":"typeList","sectionTitle":"search","types":[{"name":"Promise","type":"Promise&#60;[SearchResult](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchResult)&#60;T&#62;&#62;","optional":false,"defaultValue":"","description":"The matching hits, any requested facets,\nand the result's metadata.","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"searchMany","id":"searchmany"},{"kind":"markdown","html":"This method runs multiple search queries in a single call. Use it to run\nqueries against different indexes, or the same index with different filters,\nwithout paying for a round trip per query.\n\nDisjunctive facets are expanded here, then every query targeting the same\nprovider is handed to that provider's `searchMany` so the engine can pack\nthem into one request. Prefer `query.search` from application code, which\nhydrates the hits through graph."},{"kind":"heading","level":3,"text":"Example","id":"example-10"},{"kind":"markdown","html":"```ts\nconst results = await searchModuleService.searchMany([\n {\n entity: \"product\",\n filters: { q: \"shirt\" },\n },\n {\n entity: \"product\",\n filters: { q: \"pants\" },\n },\n])\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"searchmany-parameters"},{"kind":"typeList","sectionTitle":"searchMany","types":[{"name":"queries","type":"[SearchQuery](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchQuery)&#60;string&#62;[]","description":"The queries to run against search indexes.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"entity","type":"TEntry","description":"The name of the index to query, which defaults to the index whose name\nequals the entity.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"The dotted paths of the fields the search engine should return. Only fields\navailable in the search engine can be passed here.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"The filters to apply, including the free-text query as `q`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"pagination","type":"[SearchPagination](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchPagination)","description":"How the results are paginated and sorted.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"skip","type":"`number`","description":"The number of documents to skip before the returned hits. Mutually exclusive\nwith `cursor`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"take","type":"`number`","description":"The maximum number of hits to return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`Record<string, [SearchOrderBy](/references/types/SearchTypes/types/types.SearchTypes.SearchOrderBy)>`","description":"The fields to sort the hits by, keyed by the field's dotted path. The\nreserved `_score` key sorts by relevance.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cursor","type":"`string`","description":"An opaque provider cursor, as returned in a previous result's\n`metadata.next_cursor`. Mutually exclusive with `skip`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"search_options","type":"[SearchOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchOptions)","description":"The options changing how the query is matched, scored, and aggregated.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"attributes_to_search_on","type":"`string`[]","description":"The dotted paths of the fields to match the free-text query against. Defaults\nto every field marked `searchable` on the index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"match_strategy","type":"[SearchMatchStrategy](/references/types/SearchTypes/types/types.SearchTypes.SearchMatchStrategy)","description":"How query terms combine.\n\n- `\"all\"` (default): every term must appear as a complete token.\n- `\"any\"`: at least one term must match.\n- `\"last\"`: typeahead. Completed terms must match in full; the last term\n is a prefix, so `\"my sear\"` matches `\"My search results\"`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"typo_tolerance","type":"`boolean`","description":"Whether to match terms that are misspelled by a character or two.\nit is ignored unless the query includes a free-text `q` and the\nsearched fields have typo tolerance enabled in the index's `settings.typo_tolerance`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facets","type":"(`string` \\| [SearchFacetRequest](/references/types/SearchTypes/types/types.SearchTypes.SearchFacetRequest))[]","description":"The facets to compute alongside the hits. A string is shorthand for a `value`\nfacet on that field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disjunctive_facets","type":"`boolean`","description":"Compute each facet ignoring the filter on that same field, so a storefront\nkeeps showing sibling values of an active filter. Needs one query per facet\non every engine reviewed, so the module expands them and hands the set to\n`provider.searchMany`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"highlight","type":"`boolean` \\| [SearchHighlightOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchHighlightOptions)","description":"How the matched terms are highlighted in the returned hits. Applied only\nwhen the query includes a free-text `q`; otherwise it is ignored.\n\n`true` highlights every field the query searches on. Pass an object to pick\nfields, tags, or snippet cropping.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"distinct","type":"`string`","description":"Return at most one hit per distinct value of this field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_score","type":"`number`","description":"Discard hits scoring below this threshold.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_score","type":"`boolean`","description":"Whether to return each hit's relevance score.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locales","type":"`string`[]","description":"Query-time language hint, e.g. `[\"en\"]`. Engines that analyze per language\n(Meilisearch, Algolia) use it to pick the analyzer; a provider that cannot\nhonour it rejects it rather than silently matching differently. Neither\nfirst-party provider does: configure the analyzer language on the provider\n(postgres) or on the field (Medusa) instead.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"vector","type":"[SearchVectorOptions](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchVectorOptions)","description":"The options of a vector, or semantic, search to run instead of, or alongside,\nthe free-text query.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"[SearchCountStrategy](/references/types/SearchTypes/types/types.SearchTypes.SearchCountStrategy)","description":"How the total number of matching documents is computed. `\"exact\"` may be\nrejected or slow depending on the provider.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Escape hatch for engine features the interface does not model, keyed by\nprovider identifier, e.g. `{ typesense: { drop_tokens_threshold: 0 } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"context","type":"[QueryContextType](/references/types/CommonTypes/types/types.CommonTypes.QueryContextType)","description":"The context passed to the `query.graph` call during hydration.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"searchmany-returns"},{"kind":"typeList","sectionTitle":"searchMany","types":[{"name":"Promise","type":"Promise&#60;[SearchResult](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchResult)&#60;Record&#60;string, unknown&#62;&#62;[]&#62;","optional":false,"defaultValue":"","description":"The list of search results, in the same\norder as the queries.","expandable":false,"children":[{"name":"SearchResult&#60;Record&#60;string, unknown&#62;&#62;[]","type":"[SearchResult](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchResult)&#60;Record&#60;string, unknown&#62;&#62;[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"upsertDocuments","id":"upsertdocuments"},{"kind":"markdown","html":"This method adds documents to an index, replacing any document that already\nexists under the same ID.\n\nPrefer keeping an index up to date through its definition's `events` and\n`consume` functions. Use this method for documents that no event describes,\nsuch as data coming from a third-party system.\n\nThe returned task isn't waited on. A provider that applies writes lazily\nleaves the task's status as `enqueued`, and it's the caller's choice whether\nreading its own write back matters enough to wait for the task."},{"kind":"heading","level":3,"text":"Example","id":"example-11"},{"kind":"markdown","html":"```ts\nconst task = await searchModuleService.upsertDocuments({\n index: \"product\",\n documents: [\n {\n id: \"prod_123\",\n title: \"Shirt\",\n },\n ],\n})\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"upsertdocuments-parameters"},{"kind":"typeList","sectionTitle":"upsertDocuments","types":[{"name":"input","type":"`object`","description":"The documents to write.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"index","type":"`string`","description":"The name of the index to write to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"documents","type":"[SearchDocument](/references/types/SearchTypes/types/types.SearchTypes.SearchDocument)[]","description":"The documents to write. Each\ndocument must have an `id` property holding the index's primary key.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"upsertdocuments-returns"},{"kind":"typeList","sectionTitle":"upsertDocuments","types":[{"name":"Promise","type":"Promise&#60;[SearchTask](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchTask)&#62;","optional":false,"defaultValue":"","description":"The write's task.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID identifying the write in the search engine, which is passed back to\nthe provider's `waitForTask` method. It's set only for a deferred write,\nsince a provider applying writes inline has nothing to identify.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"`string`","description":"The name of the index the write was applied to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[SearchTaskStatus](/references/types/SearchTypes/types/types.SearchTypes.SearchTaskStatus)","description":"The write's status.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"error","type":"`object`","description":"The error that made the write fail, if its `status` is `failed`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"message","type":"`string`","description":"The error's message.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"The error's code, as reported by the search engine.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]}]}