medusa
medusa copied to clipboard
Quickstart guide: MeiliSearch plugin for Medusa doesn't create MeiliSearch index
Bug report
MeiliSearch plugin for Medusa doesn't create MeiliSearch index when following Quickstart guide.
Describe the bug
I am following the Quickstart guide and are trying to enable the MeiliSearch plugin for Medusa.
Storefront:
.env
NEXT_PUBLIC_SEARCH_APP_ID= NEXT_PUBLIC_SEARCH_ENDPOINT=http://127.0.0.1:7700 NEXT_PUBLIC_SEARCH_API_KEY=3fab... NEXT_PUBLIC_SEARCH_INDEX_NAME=products
store.config.json
{ "features": { "search": true } }
Backend: .env MEILISEARCH_HOST=http://127.0.0.1:7700 MEILISEARCH_API_KEY=3fab...
medusa-config.js
{ resolve:medusa-plugin-meilisearch, options: { // config object passed when creating an instance // of the MeiliSearch client config: { host: process.env.MEILISEARCH_HOST, apiKey: process.env.MEILISEARCH_API_KEY, }, settings: { products: { indexSettings: { searchableAttributes: [ "title", "description", "variant_sku", ], displayedAttributes: [ "title", "description", "variant_sku", "thumbnail", "handle", ], }, primaryKey: "id", transform: (product) => ({ id: product.id, // other attributes... }), }, }, }, },
System information
Medusa version (including plugins): 1.8.0. Node.js version: 16 Database: Postgres Operating system: Mac OS X Ventura 13 Browser (if relevant): Latest Chrome
Steps to reproduce the behavior
- Go to Quickstart guide and follow MeiliSearch search setup steps
- Restart both storefrond and backend
- Edit/update products to trigger indexing
- Try to search on the store front
- Storefront produces error:
Unhandled Runtime Error Error: MeiliSearchCommunicationError: Index products not found.
Expected behavior
Products index should be created, search should return results. The docs state:
The Medusa backend must also have an event bus module installed, which is available when using the default Medusa backend starter.
Even bus should be present by default and index created by medusa backend?
Screenshots
Storefront error:
Meilisearch admin shows that indeed there is no products index created by Medusa:
Hi,
I had the same problem as you having now. My solution was to upgrade Medusa and the search-plugin to the latest. Another thing to test is the meilesearch service. If it's a local setup, you can try with a free tier account on meilesearch instead. Just to see if it is the api-key or something else that is acting spokey.
Hope it helps!
Hi @oliwerhelsen,
I just updated @medusajs/medusa to 1.11.0 and medusa-plugin-meilisearch to 2.0.5 but it's still a no-go. I'm hitting the same wall as before with the products index not getting created.
Wondering if there's a step I'm missing with the index creation, like a manual step not documented, or if it's something the medusa backend should be handling automatically?
@vladimirpekez – have you tried to trigger the search indexing of products manually?
@olivermrbl No - how to do that, it this step in the docs?
Can I get you to try to fire the following SQL query:
insert into staged_job (id, event_name, data) values ('test', 'SEARCH_INDEX_EVENT', '{}')
@olivermrbl
Sure, I see backend process it with a warning:
info: Processing SEARCH_INDEX_EVENT which has 1 subscribers warn: This is an empty method: addDocuments must be overridden by a child class
If I check Meilisearch console afterwards I see no index is created.
@vladimirpekez – Your Meilisearch plugin is not getting registered.
Can you share your medusa-config.js in a gist, as I cannot read what you've included in the issue description.
@olivermrbl Sure here it is: https://gist.github.com/vladimirpekez/1e1cb8f35a708c1d680a5005bb397978
I just used the quickstart sample as per quickstart documentation.
I just followed the quickstart myself and was unable to reproduce your issue.
I carried out the following steps:
1. ran 'yarn create medusa-app'
2. set up postgres
3. ran 'yarn seed'
4. ran 'yarn add medusa-plugin-meilisearch@latest'
5. added the config you've posted here to 'plugins'
6. ran 'yarn start'
7. search indexing event was triggered and products were indexed successfully
Can I get you to try this once more from the beginning?
@olivermrbl When doing the exact steps above I get:
info: Processing SEARCH_INDEX_EVENT which has 1 subscribers error: An error occurred while processing SEARCH_INDEX_EVENT: MeiliSearchApiError: The provided API key is invalid.
I just tried generating the Meili Search API key again and got the same error, I used the quickstart curl request:
curl \
-X POST 'http://127.0.0.1:7700/keys'
-H 'Content-Type: application/json'
-H 'Authorization: Bearer 3a5rEL6cSOuSfxhC0TaibILFFnufNLXkArPkdbAb3wU'
--data-binary '{
"description": "Search products",
"actions": ["search"],
"indexes": ["products"],
"expiresAt": "2024-01-01T00:00:00Z"
}'
which returns:
{"name":null,"description":"Search products","key":"dea2518b53fba712bb81b7b60d4c1d3c049e4c191a6e20b35f2fda94d2f0e1fd","uid":"f02d657c-d230-475a-8b8b-6664a88828e2","actions":["search"],"indexes":["products"],"expiresAt":"2024-01-01T00:00:00Z","createdAt":"2023-05-18T21:36:18.987421Z","updatedAt":"2023-05-18T21:36:18.987421Z"}%
running in docker always fails to create the index, console shows that no search engine is configured. running the project locally and i was able to see the index but no product in there :/
Fixed for me after upgrading packages as shown in #4159
@amirping I have overcome this problem. If you're running your app in docker-compose, connect to it not through http://localhost:7700, but through container hostname, i.e. meilisearch:7700. Moreover, you can add a named network with bridge driver, instead of the default one.
not working for me , i'm facing the same problem
when putting NEXT_PUBLIC_SEARCH_ENDPOINT=http://quirky_gagarin:7700
the error Error: MeiliSearchCommunicationError: Failed to fetch occurs again
@olivermrbl When doing the exact steps above I get:
info: Processing SEARCH_INDEX_EVENT which has 1 subscribers error: An error occurred while processing SEARCH_INDEX_EVENT: MeiliSearchApiError: The provided API key is invalid.
I just tried generating the Meili Search API key again and got the same error, I used the quickstart curl request:
curl \ -X POST 'http://127.0.0.1:7700/keys' -H 'Content-Type: application/json' -H 'Authorization: Bearer 3a5rEL6cSOuSfxhC0TaibILFFnufNLXkArPkdbAb3wU' --data-binary '{ "description": "Search products", "actions": ["search"], "indexes": ["products"], "expiresAt": "2024-01-01T00:00:00Z" }'
which returns:
{"name":null,"description":"Search products","key":"dea2518b53fba712bb81b7b60d4c1d3c049e4c191a6e20b35f2fda94d2f0e1fd","uid":"f02d657c-d230-475a-8b8b-6664a88828e2","actions":["search"],"indexes":["products"],"expiresAt":"2024-01-01T00:00:00Z","createdAt":"2023-05-18T21:36:18.987421Z","updatedAt":"2023-05-18T21:36:18.987421Z"}%
did you pass the api key as a value for NEXT_PUBLIC_SEARCH_API_KEY in nextjs env file ?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days.
This issue was closed because it has been stalled for 3 days with no activity.