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

Type errors while using Response.hits attrs #1897

Open
realsuayip opened this issue Sep 3, 2024 · 3 comments
Open

Type errors while using Response.hits attrs #1897

realsuayip opened this issue Sep 3, 2024 · 3 comments

Comments

@realsuayip
Copy link

Since the returned type is actually AttrList rather than plain list, accessing those attributes will result in type errors.

e.g.,

error: "List[Hit]" has no attribute "total" [attr-defined]

@miguelgrinberg
Copy link
Collaborator

Yes. Typing isn't complete in the current release. We are working on typing all the Elasticsearch structures including queries and responses, but that will come in a later release.

@giovannipcarvalho
Copy link

The same thing happens for response.hits.hits.

Will accessing .hits.hits still be supported in the future, or should we use .hits instead?

@miguelgrinberg
Copy link
Collaborator

If you use .hits.hits you are accessing the raw response from Elasticsearch. When you use .hits you are accessing the results after being processed by this library, which in my opinion is preferable. The way this is implemented right now is confusing, but my hope is that .hits.hits will give you access to the unmodified response (possibly with missing or generic typing) and .hits will provide access with correct typing.

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

3 participants