-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
searchableAttributes
change order of fields in response hits
#1495
Comments
To reproduce, you should add this as setting:
|
Hello! @MarinPostma (Please, tell me if it's not related to the transplant code), can we keep the order of the fields of the initial document in the response to be ISO with 0.20?
|
Not possible, this is tied to the representation on the documents in milli @Kerollmops |
Indeed, it can't be returned in the original order, it can only be returned in the |
Thanks! If I understand correctly the user must rewrite all these initially ordered fields in In this case, he will not search on specific fields and the Should we explain this somewhere to guide users and make it clear that the order can no longer be guaranteed from the moment |
TBH it should not matter. JSON are manipulated programatically, and the order is irrelevant. We make assumptions on the order of the fields at indexing, but the JSON spec specifies that a json object is unordered. Implementation of json deserializer may not preserve order. |
Thanks for the clarification, @MarinPostma 👍. Indeed, this is something that should be clarified in this way. I think of the user who might wonder why and not being able to find an answer. |
@MarinPostma however we use a linked hashmap to keep the order when indexing. As long as the |
@qdequele the fieldId doubles as field position, that's why |
Does |
@dichotommy nope |
Even if the order is relevant in JSON, this behavior can impact the front-end. Cf the mini-dashboard: we clearly see the switch of the fields. |
@curquiza Is this not fixed with this meilisearch/milli/pull/293 ? |
Nope, it's not in the v0.21.0 milestones. You can check it directly on the issue I was not there when the decision of removing this from the v0.21.0 was made, but, by reading this issue, it does not seem to be an easy fix since we don't know how to do it. |
searchableAttributes
change order of fields in response hits
I created a draft PR not only to declare my intention to fix this issue but also to provide a reproduction case to anyone who decided to make their own attempt. |
Oh, This is a tricky one. I spent quite some time locating the cause and still could not figure out the best approach to fix it. So let me explain the logic that leads to undesirable output first:
The whole week I thought about this issue, and I think, in the current implementation, this could not be definitely identified as a bug. Because there are other cases when the order of fields in the original document is not preserved. For example, if we add the first document with fields I think this issue can not be solved without the introduction of additional metadata, which will preserve field order disregarding all other settings. But only if you decide this is a bug, not a feature. |
@curquiza please, take a look at the previous comment. I believe this issue requires an additional round of triage. |
Reordering of fields occurs in |
Here are the reproduction steps for the scenario I mentioned:
|
Thank you very much for your investigation @mou, We have been aware of the issue for a long time and would like to take the time to fix that. Unfortunately, this is a quite complex feature to implement, we will prioritize that in the future. This is related to the internal way we store the documents, the current system is efficient in storing the documents without taking up too much space, but it can be improved a lot by compressing the documents, for example. The new design of this system should try to compress the documents and also keep the order of the fields. |
@Kerollmops, so, if you have already decided to reimplement document storage with new requirements, then I do not see any reason for trying to fix this issue in the current architecture. Or I did not understand you well? Also, feel free to discard my draft PR with the test case. |
Indeed, we want to do a bunch of optimization on the way we store our documents internally to consume less space, and we will evaluate the amount of work required to keep the original order of the fields at this moment. Thank you very much for your PR, but we will not keep it as you correctly pointed out that we will refactor many of the code parts related to this behavior, and your PR will likely be outdated by then ❤️ |
Ok. I will close it then. |
Discussed with @Kerollmops: could be done once the Meilisearch DB storage will be re-worked. |
Describe the bug
When adding fields in
searchableAttributes
the order of fields in the returned document are impacted:id
field of document goes from first position to second position.Given this document:
after a search this is how it is returned in the response body:
Expected behavior
Same order
MeiliSearch Version: 0.21.0
The text was updated successfully, but these errors were encountered: