Skip to content

Inconsistent behavior with body and index parameter order in the search method #2706

Closed
@ISMendys

Description

@ISMendys

When using the search method in the Elasticsearch client library, I encountered an unexpected behavior where the order of the body, index, and size parameters affects the function's operation. Here are the details:

Working code (as expected):

es = get_elastic()
body = {"query": {"terms": {"_id": ids, "boost": 1.0}}}
try:
    response = es.search(index=index, body=body, size=len(ids))
except Exception as error:
    logging.error(error, exc_info=True)
    raise error

In this case, with index first, followed by body and size, the search works as expected.

Code that throws an error:

When the order of parameters is reversed, placing body before index, the search fails:

es = get_elastic()
body = {"query": {"terms": {"_id": ids, "boost": 1.0}}}
try:
    response = es.search(body=body, index=index, size=len(ids))
except Exception as error:
    logging.error(error, exc_info=True)
    raise error

Here, the search does not work, and the only relevant difference between these cases is the parameter order.

Code where the reversed order does not cause an error:

Even with body and index reversed, the search works when size is not used:

response = es.search(body=body, index=index)

Summary of unexpected behavior: This inconsistency appears specifically when adding the size parameter (elasticsearch version 8.15.0) while reversing the order of body and index. The expected behavior is for the search method to work regardless of parameter order as long as all provided parameters are valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions