medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Quickstart guide: MeiliSearch plugin for Medusa doesn't create MeiliSearch index

Open vladimirpekez opened this issue 2 years ago • 15 comments
trafficstars

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

  1. Go to Quickstart guide and follow MeiliSearch search setup steps
  2. Restart both storefrond and backend
  3. Edit/update products to trigger indexing
  4. Try to search on the store front
  5. 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: image

Meilisearch admin shows that indeed there is no products index created by Medusa: image

vladimirpekez avatar May 16 '23 07:05 vladimirpekez

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!

oliwerhelsen avatar May 16 '23 11:05 oliwerhelsen

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 avatar May 16 '23 14:05 vladimirpekez

@vladimirpekez – have you tried to trigger the search indexing of products manually?

olivermrbl avatar May 16 '23 15:05 olivermrbl

@olivermrbl No - how to do that, it this step in the docs?

vladimirpekez avatar May 16 '23 16:05 vladimirpekez

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 avatar May 16 '23 16:05 olivermrbl

@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 avatar May 17 '23 05:05 vladimirpekez

@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 avatar May 17 '23 10:05 olivermrbl

@olivermrbl Sure here it is: https://gist.github.com/vladimirpekez/1e1cb8f35a708c1d680a5005bb397978

I just used the quickstart sample as per quickstart documentation.

vladimirpekez avatar May 17 '23 14:05 vladimirpekez

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 avatar May 18 '23 07:05 olivermrbl

@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"}%

vladimirpekez avatar May 19 '23 03:05 vladimirpekez

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 :/

amirping avatar Jun 07 '23 16:06 amirping

Fixed for me after upgrading packages as shown in #4159

lrocher91 avatar Jun 08 '23 15:06 lrocher91

@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.

levshkatov avatar Jun 13 '23 10:06 levshkatov

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

Screenshot 2024-06-22 at 3 18 39 am

codecret avatar Jun 22 '24 00:06 codecret

@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 ?

codecret avatar Jun 22 '24 00:06 codecret

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.

github-actions[bot] avatar Dec 28 '24 01:12 github-actions[bot]

This issue was closed because it has been stalled for 3 days with no activity.

github-actions[bot] avatar Jan 20 '25 01:01 github-actions[bot]