In this document, you’ll learn what a search service is and how it’s used in Medusa.
A search service is used to manage search indices of searchable items, such as products, and providing results for search operations. Although the Medusa core provides basic search functionalities through its API Routes, a search service allows you to integrate third-party services for an optimized search experience and rich search functionalities.
src/services directory of your Medusa backend codebase or plugin. The class must extend the
AbstractSearchService class imported from the
Using the dependency container and injection, the Medusa backend will then use and resolve the search service within the backend’s search operations, such as when the Search Products API Route is used. You can also resolve the service within your resources to trigger the search where necessary.
Medusa provides official plugins that you can install and use in your Medusa backend. Check out available search plugins here.
Hierarchy of Search Services
Medusa provides a default search service that doesn’t actually perform any indexing or searching, but acts like a placeholder search service. Only one search service is registered in the dependency container under the
If you install a search plugin, the search service within it will be registered in the dependency container and used throughout the Medusa backend.
If you create your own search service in the Medusa backend codebase, it will be registered in the dependency container and used throughout the Medusa backend.
Developers can create a custom search service with the desired functionality or third-party integration either directly within the Medusa Core, in a plugin, or in a module.
Learn how to create a search service.