Skip to content
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

Sorting on nested object fields is not handled preperly #1891

Open
jhdxr opened this issue Aug 30, 2024 · 1 comment
Open

Sorting on nested object fields is not handled preperly #1891

jhdxr opened this issue Aug 30, 2024 · 1 comment

Comments

@jhdxr
Copy link

jhdxr commented Aug 30, 2024

Say for a sort like this

s = Search(using=client, index=source)
s = s.sort("metadata.date")

Won't work because ES will complain "it is mandatory to set the [nested] context on the nested sort field: [metadata.date].

To fix it, you should use raw query, which means something like this

s = s.sort({
       "metadata.date": {
            "order": "asc", 
            "nested": {
                "path": "metadata"
            }
     }
})

While I think it makes sense for ES and the elasticsearch-py library ask user to do so, elasticsearch-dsl is not the case. This library is aimed to avoid writing raw query, and it should be able to infer that if the fields is nested or not, and generated the path accordingly if necessary.

@miguelgrinberg
Copy link
Collaborator

Hi! Yes, I agree, we should be able to create the correct sort format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants