medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.1k stars 2.63k forks source link

How to disable default 'products' search index? #4298

Open levshkatov opened 1 year ago

levshkatov commented 1 year ago

Bug report

I use the meilisearch plugin and when I enable it, without any indexes, it creates a default 'products' index and queues all my products from the database. And I think it happens whenever I restart the application. I found that this loader emits a search event. After that, this subscriber starts to retrieve all my products with a bunch of relations no matter whether I need it or not. I definitely need a search engine and now I only can disable the meilisearch plugin and write another one with the property isDefault=true. Is it possible to disable default indexing without writing my own plugin?

System information

Medusa version (including plugins): 1.12.0, meilisearch: 2.0.7 Node.js version: Database: Operating system: Browser (if relevant):

Steps to reproduce the behavior

  1. Add medusa-plugin-meilisearch without any indexes
  2. Start the app
  3. Enable Postgres logging
  4. Notice that it created a 'products' index and queued all products

Expected behavior

Please, remove emitting SEARCH_INDEX_EVENT and delegate it to userland's emitters and subscribers. Or, please, rewrite it in a way it won't trigger at every app's start.

tsvetann commented 1 year ago

What are you trying to achieve? What is your use case for meilisearch?

levshkatov commented 1 year ago

@tsvetann I'm trying to achieve not grabbing all my products every time I start the application. I wrote custom indexes for my needs, thus I need meilisearch. The point of this bug report is that now if we enable meilisearch even without indexes (I suppose algolia too), we select all of the products at app startup.

tonhuynhit commented 12 months ago

We got the same issue which impacts to performance when scaling out the server.

RegisHubelia commented 10 months ago

Yes - we should have an option not to reindex on startup - on kubernetes, if you scale up, it can render the store unusable...

voronovmaksim commented 2 months ago

I had the same issue.

Moreover i update the index in runtime(add new filterableAttributes) but after startup index is reseted and so my runtime filterableAttributes are deleted from index.

RC of the issue is the meilisearch loader. It calls update Index during startup(https://github.com/medusajs/medusa/blob/4fedaae01e93c10f37ae90d70af3dd70614b5683/packages/medusa-plugin-meilisearch/src/loaders/index.ts#L20) with hardcoded filterableAttributes in medusa-config. So my runtime filterableAttributes are lost.

I can not find a way to override the loader apart from delete the file from dist)