You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the problem including expected versus actual behavior:
I am encountering a type mismatch error when attempting to use the Elasticsearch.search method with the fields parameter to retrieve a subset of stored fields from matched documents. According to the Elasticsearch documentation, passing a list of field names as strings to the fields parameter should be sufficient for this purpose Elasticsearch Fields Request.
However, when I specify the fields parameter as a list of strings, both Pylance and PyCharm raise type errors indicating that the expected type is t.Optional[t.Sequence[t.Mapping[str, t.Any]]], rather than t.Optional[t.Union[str, t.Sequence[str]]]. This discrepancy seems inconsistent with the type hints used in other methods like search_mvt or knn_search, where the fields parameter accepts a union of string or sequence of strings.
Despite the type checking errors reported by the IDEs, the actual execution of the search query does yield the expected results, with the returned hits including the requested fields. It appears that the type hints may need updating to reflect the correct usage of the fields parameter for the search method.
In this snippet, fields is passed as a list of strings, but the type hint suggests that a sequence of mappings is expected. This leads to the type error in Pylance and PyCharm:
Could the type hint for the fields parameter in the search method be updated to align with the expected usage, or is there another way to address this issue without changing the type hint? Am I misunderstanding how to use the fields parameter?
The text was updated successfully, but these errors were encountered:
Hey @mpaluch92, thank you for your detailed bug report. You are right that passing a list of string is supported and that the type annotation is wrong. In fact, this was initially reported by @JannKleen in #2347, and I forgot to reopen the issue when I realized my fix had to be reverted.
The rest of this comment gives more technical details, but you can ignore them. I'll close this issue when I fix the bug.
Long story short, I need to fix the (private) Python code generator to take into account shortcut_property and fix the type hints. In the meantime, you may need # pyright: ignore or # mypy: ignore annotations, sorry.
Elasticsearch version:
8.12.0
elasticsearch-py
version:8.12.0
Description of the problem including expected versus actual behavior:
I am encountering a type mismatch error when attempting to use the
Elasticsearch.search
method with thefields
parameter to retrieve a subset of stored fields from matched documents. According to the Elasticsearch documentation, passing a list of field names as strings to thefields
parameter should be sufficient for this purpose Elasticsearch Fields Request.However, when I specify the
fields
parameter as a list of strings, both Pylance and PyCharm raise type errors indicating that the expected type ist.Optional[t.Sequence[t.Mapping[str, t.Any]]]
, rather thant.Optional[t.Union[str, t.Sequence[str]]]
. This discrepancy seems inconsistent with the type hints used in other methods likesearch_mvt
orknn_search
, where thefields
parameter accepts a union of string or sequence of strings.Despite the type checking errors reported by the IDEs, the actual execution of the search query does yield the expected results, with the returned hits including the requested fields. It appears that the type hints may need updating to reflect the correct usage of the
fields
parameter for thesearch
method.Steps to reproduce:
In this snippet,
fields
is passed as a list of strings, but the type hint suggests that a sequence of mappings is expected. This leads to the type error in Pylance and PyCharm:Could the type hint for the
fields
parameter in thesearch
method be updated to align with the expected usage, or is there another way to address this issue without changing the type hint? Am I misunderstanding how to use thefields
parameter?The text was updated successfully, but these errors were encountered: