Errors using filters for analytics queries with AppSearch Python client API

Hello, I will appreciate some help to explain what is the correct way to use analytics filters with the AppSearch python client API?

I have an engine running in AppSearch and I want to track clicks and queries through tags. The AppSearch Analytics UI is good, but I want to download the data and do my own analysis. So I’m testing access through the Python API.
Looking the documentation at and
I couldn’t find any example of using the following functions


The functions are here:

I want to translate the following Analytic query to the API

curl -X POST "https:/" ^
-H "Content-Type: application/json" ^
-H "Authorization: Bearer private-xxxxxxxxxxxxx" ^
-d "{'filters': {'all': [{ 'tag': ['my-tag'] },  { 'date': { 'from': '2021-08-10T12:00:00+00:00', 'to': '2021-10-15T00:00:00+00:00'} } ] } }" "

A snippet of my code:

app_search = AppSearch(api_endpoint, http_auth= private_key)

signed_search_key = app_search.create_signed_search_key(
    api_key= app_search.http_auth,
        "body": {}
my_filter1 = {'all': [{'tag': ['my-tag']}, {'date': {
    'from': '2021-08-10T12:00:00+00:00', 'to': '2021-10-15T00:00:00+00:00'}}]}
my_filter2 = {'filters': {'all': [{'tag': ['my-tag']}, {'date': {'from': '2021-08-10T12:00:00+00:00', 'to': '2021-10-15T00:00:00+00:00'}}]}}

print(app_search.get_top_queries_analytics(engine_name, filters=my_filter1))
print(app_search.get_top_queries_analytics(engine_name, filters=my_filter2))

Querying the engine without any filter works well , but when I use a filter (either of them) it gives the following error:

Traceback (most recent call last):
  File "c:/…my-project/", line 30, in <module>
    print(app_search.get_top_queries_analytics(engine_name, filters=my_filter2))
  File "…py38\lib\site-packages\elastic_enterprise_search\client\", line 3656, in get_top_queries_analytics
    return self.perform_request(
  File "…-py38\lib\site-packages\elastic_enterprise_search\client\", line 187, in perform_request
    return self.transport.perform_request(
  File "…-py38\lib\site-packages\elastic_transport\", line 311, in perform_request
    resp_status, resp_headers, data = connection.perform_request(
  File "…-py38\lib\site-packages\elastic_transport\connection\", line 251, in perform_request
  File "…-py38\lib\site-packages\elastic_transport\connection\", line 192, in _raise_error
    raise HTTP_EXCEPTIONS.get(status, APIError)(
elastic_transport.exceptions.BadRequestError: [400] {'errors': ['Filters contains an invalid value for item inside of field: filters root; must be an object']}

I’m still quite new to elastic, so any help on what is the correct way to format filters with the API will be really appreciated!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.