Support Meilisearch v1.0.0+ #3277
Replies: 4 comments 4 replies
-
I haven't published my fix, but someone on Discord was asking about this so I just popped the files in a repo in case it's useful to anyone |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing this @rub1e, indeed, reverting the server to |
Beta Was this translation helpful? Give feedback.
-
All it takes is a POST request and v1+ will work just fine. I think Meili wrote something about this in the changelog too |
Beta Was this translation helpful? Give feedback.
-
Thanks @rub1e - highly appreciate the elaborate description of your issues as well as the input on how to resolve them. I've had a look at Meilisearch v1.0.0, and I believe we can come up with a solution fairly quickly that fixes the issues and meets your additional requirements. Note, you'll find that the proposed changes are very similar to what you've already mentioned. Therefore, I might repeat some things, but I just want to flesh it out in full to not have the context for the changes live in a different message. ChangesPrimary key inferenceMeilisearch has improved their primary key inference mechanism such that it tries to detect the key upon receiving documents for the first time. It does this by searching for a single field that ends with Proposal Important: This will be a breaking change, as we will move the provider-specific index settings to a nested property In
The The primary key is applied in the method Custom document transformerCurrently, users wishing to store documents in a specific shape will not be able to use our Meilisearch plugin as is. It would be a big improvement to be able to store Medusa entities in a shape that fits businesses' exact requirements. Proposal In
With the above configuration, Meilisearch will only store the id of Medusa products. Let me know what you think about these proposals @rub1e :) Also, I took the liberty of creating a draft PR with a first take on the implementation. |
Beta Was this translation helpful? Give feedback.
-
Last week, Meilisearch v1.0.0 was released. As a result of changes to the way they handle primary key inference, anyone following the Medusa docs for using Meilisearch will be unable to use the Meilisearch plugin.
The problem - meilisearch
If your documents have multiple keys like
id
andcollection_id
, Meilisearch won't index them by default, because it won't choose a primary key. And it won't return an error, because it only ever returns 202 for accepting a task.Since this applies to the Medusa seed data, a new user following the docs won't have their documents indexed, and they won't get any feedback as to why. (Yes, I spent more than the weekend figuring that out 😞 )
The problem - medusa-plugin-meilisearch
The obvious solution is to just set the primary key at the point of index creation. The problem with that is, as far I can tell, the
SearchService
'screateIndex
method isn't actually calledFrom what I can see, the way it works is that the first call to Meilisearch is from the
updateSettings
method and that's what creates the index. But since you can't set the primary key this way, the index is always created without a primary key. Which means the subsequent call toaddDocuments
will fail.(Temporary) Solution
The fix for this is very easy - I just create the index and set the primary key in
updateSettings
This means that the call to
createIndex
is always made, but Meilisearch just ignores it so it's not the end of the world in the short term. Of course this does mean the primary key is hardcoded; plus there's a race condition as you have to rely on the index being created by the timeaddDocuments
is called; so it's a hack, not really a pushable fix.A more permanent solution would involve changing the way the
SearchService
module is used, and callingcreateIndex
first. Then the user could set their own primary key in the config.(Another thing I'd like to do is be able to set my own
transformDocuments
function in config)My partner and I would happily devote some time to this, as we intend to use Meilisearch with Medusa going forward, but I thought it would be best to start this discussion first. I know Medusa is in very active development so perhaps there are already ideas floating around for the future of the search service and plugins. Looking forward to hearing people's thoughts on this. 😃
Beta Was this translation helpful? Give feedback.
All reactions