// This file is autogenerated, DO NOT EDIT
// rest-api/security/query-api-key.asciidoc:729

[source, python]
----
resp = client.security.query_api_keys(
    size=0,
    query={
        "bool": {
            "filter": {
                "term": {
                    "invalidated": True
                }
            }
        }
    },
    aggs={
        "invalidated_keys": {
            "composite": {
                "sources": [
                    {
                        "username": {
                            "terms": {
                                "field": "username"
                            }
                        }
                    },
                    {
                        "key_name": {
                            "terms": {
                                "field": "name"
                            }
                        }
                    }
                ]
            }
        }
    },
)
print(resp)
----
