---
title: "Query roles"
method: POST
path: "/api/security/role/_query"
---

# Query roles

`POST /api/security/role/_query`

Query Kibana roles with optional filters, paging, and sorting.

## Headers

- `kbn-xsrf` string, required

## Request body

- KibanaHTTPAPIsSecurityQueryRolesBody — The request body for querying roles.
  - `filters` KibanaHTTPAPIsSecurityQueryRolesFilters — The filter criteria for the query.
    - `showReservedRoles` boolean
  - `from` number
  - `query` string
  - `size` number
  - `sort` KibanaHTTPAPIsSecurityQueryRolesSort — The sort criteria for the query.
    - `direction` 'asc' | 'desc', required
    - `field` string, required

## Response `200`

Indicates a successful call.

- KibanaHTTPAPIsSecurityQueryRolesResponse — The response payload for a roles query.
  - `count` number, required — The number of roles returned in this response page.
  - `roles` KibanaHTTPAPIsSecurityRoleResponse[], required
    - `_transform_error` KibanaHTTPAPIsSecurityRoleTransformError[]
      - `reason` string, required — The reason the role could not be fully transformed.
      - `state` KibanaHTTPAPIsSecurityRoleKibanaApplication[]
        - `application` string, required
        - `privileges` string[], required
        - `resources` string[], required
    - `_unrecognized_applications` string[]
    - `description` string — A description for the role.
    - `elasticsearch` KibanaHTTPAPIsSecurityRoleElasticsearch, required — The Elasticsearch cluster, index, and remote cluster security privileges for the role.
      - `cluster` string[]
      - `indices` KibanaHTTPAPIsSecurityRoleIndicesPrivileges[]
        - `allow_restricted_indices` boolean — Restricted indices are a special category of indices that are used internally to store configuration data and should not be directly accessed. Only internal system roles should normally grant privileges over the restricted indices. Toggling this flag is very strongly discouraged because it could effectively grant unrestricted operations on critical data, making the entire system unstable or leaking sensitive information. If for administrative purposes you need to create a role with privileges covering restricted indices, however, you can set this property to true. In that case, the names field covers the restricted indices too.
        - `field_security` object
        - `names` string[], required
        - `privileges` string[], required
        - `query` string — A search query that defines the documents the role members have read access to. A document within the specified data streams and indices must match this query in order for it to be accessible by the role members.
      - `remote_cluster` KibanaHTTPAPIsSecurityRoleRemoteClusterPrivileges[]
        - `clusters` string[], required
        - `privileges` string[], required
      - `remote_indices` KibanaHTTPAPIsSecurityRoleRemoteIndicesPrivileges[]
        - `allow_restricted_indices` boolean — Restricted indices are a special category of indices that are used internally to store configuration data and should not be directly accessed. Only internal system roles should normally grant privileges over the restricted indices. Toggling this flag is very strongly discouraged because it could effectively grant unrestricted operations on critical data, making the entire system unstable or leaking sensitive information. If for administrative purposes you need to create a role with privileges covering restricted indices, however, you can set this property to true. In that case, the names field will cover the restricted indices too.
        - `clusters` string[], required
        - `field_security` object
        - `names` string[], required
        - `privileges` string[], required
        - `query` string — A search query that defines the documents the role members have read access to. A document within the specified data streams and indices must match this query in order for it to be accessible by the role members.
      - `run_as` string[]
    - `kibana` KibanaHTTPAPIsSecurityRoleKibanaPrivilegeResponse[], required
      - `_reserved` string[]
      - `base` string[], required
      - `feature` object, required
      - `spaces` string[], required
    - `metadata` object
    - `name` string, required — The role name.
    - `transient_metadata` object
  - `total` number, required — The total number of roles that match the query.

---

[API](https://skmtc.net/elastic/apis/kibana-apis.md) · [All operations](https://skmtc.net/elastic/apis/kibana-apis/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/elastic/kibana-apis/versions/531c9e2a7d23/schema)
