---
type: api
title: Get roles
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/operation/operation-security-get-role
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/operation/operation-security-get-role
products:
  - Elasticsearch
---

# Get roles

Authentication: required

## Paths

- `GET` `/_security/role/{name}`
- `GET` `/_security/role`

#### Path parameters

- `name` (union string | string[]) — optional, leave it out to use `/_security/role`
  The name of the role.
You can specify multiple roles as a comma-separated list.
If you do not specify this parameter, the API returns information about all roles.

## Description

Get roles in the native realm.
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The get roles API cannot retrieve roles that are defined in roles files.

## Required authorization

- Cluster privileges: `read_security`

## Query string parameters

- `include_implicit` (boolean · default: false) — optional
  If `true`, include privileges that are implicitly granted by registered `ImplicitPrivilegesProviders` alongside the explicitly configured privileges.
Each implicit entry in the response is annotated with `implicitly_granted: true`.

## Response

`application/json`

- `<string>` (object)
  - `cluster` (union anyOf[])
    Values: `all`, `cancel_task`, `clone_api_key`, `create_snapshot`, `cross_cluster_replication`, `cross_cluster_search`, `delegate_pki`, `grant_api_key`, `manage`, `manage_api_key`, `manage_autoscaling`, `manage_behavioral_analytics`, `manage_ccr`, `manage_data_frame_transforms`, `manage_data_stream_global_retention`, `manage_enrich`, `manage_esql`, `manage_ilm`, `manage_index_templates`, `manage_inference`, `manage_ingest_pipelines`, `manage_logstash_pipelines`, `manage_ml`, `manage_oidc`, `manage_own_api_key`, `manage_pipeline`, `manage_reindex`, `manage_rollup`, `manage_saml`, `manage_search_application`, `manage_search_query_rules`, `manage_search_synonyms`, `manage_security`, `manage_service_account`, `manage_slm`, `manage_token`, `manage_transform`, `manage_user_profile`, `manage_watcher`, `monitor`, `monitor_data_frame_transforms`, `monitor_data_stream_global_retention`, `monitor_enrich`, `monitor_esql`, `monitor_inference`, `monitor_ml`, `monitor_reindex`, `monitor_rollup`, `monitor_snapshot`, `monitor_stats`, `monitor_text_structure`, `monitor_transform`, `monitor_watcher`, `none`, `post_behavioral_analytics_event`, `read_ccr`, `read_fleet_secrets`, `read_ilm`, `read_pipeline`, `read_security`, `read_slm`, `transport_client`, `write_connector_secrets`, `write_fleet_secrets`
  - `indices` (object[])
    - `implicitly_granted` (boolean)
      Set to `true` on entries that were contributed by a registered `ImplicitPrivilegesProvider`
rather than explicitly stored on the role. Only present when the get role API is called with
`include_implicit=true`. The put role API rejects this field, so clients must not echo it back
on a GET-then-PUT round-trip.
    - `field_security` (object)
      The document fields that the owners of the role have read access to.
      - `except` (union oneOf)
        One of: `string[]` or `string`
      - `grant` (union oneOf)
        One of: `string[]` or `string`
    - `names` (union string | string[])
      A list of indices (or index name patterns) to which the permissions in this entry apply.
    - `privileges` (union anyOf[])
      The index level privileges that owners of the role have on the specified indices.
      Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `create_view`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `delete_view`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `manage_view`, `monitor`, `none`, `read`, `read_cross_cluster`, `read_view_metadata`, `view_index_metadata`, `write`
    - `query` (union oneOf)
      A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
      - **string**
      - **[Query](https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
        An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
      - **RoleTemplateQuery**
        - `template` (object)
          When you create a role, you can specify a query that defines the document level security permissions. You can optionally
use Mustache templates in the role query to insert the username of the current authenticated user into the role.
Like other places in Elasticsearch that support templating or scripting, you can specify inline, stored, or file-based
templates and define custom parameters. You access the details for the current authenticated user through the _user parameter.
          - `source` (union oneOf)
            - **string**
            - **[Query](https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
              An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
          - `id` (string)
            The `id` for a stored script.
          - `params` (map string to object)
            Specifies any named parameters that are passed into the script as variables.
Use parameters instead of hard-coded values to decrease compile time.
          - `lang` (union anyOf · default: painless)
            Specifies the language the script is written in.

Supported values include:
  - `painless`: Painless scripting language, purpose-built for Elasticsearch.
  - `expression`: Lucene’s expressions language, compiles a JavaScript expression to bytecode.
  - `mustache`: Mustache templated, used for templates.
  - `java`: Expert Java API
            Values: `painless`, `expression`, `mustache`, `java`
          - `options` (map string to string)
    - `allow_restricted_indices` (boolean · default: false)
      Set to `true` if using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in the `names` list, Elasticsearch checks privileges against these indices regardless of the value set for `allow_restricted_indices`.
  - `remote_indices` (object[])
    - `clusters` (union oneOf)
      A list of cluster aliases to which the permissions in this entry apply.
      One of: `string[]` or `string`
    - `field_security` (object)
      The document fields that the owners of the role have read access to.
      - `except` (union oneOf)
        One of: `string[]` or `string`
      - `grant` (union oneOf)
        One of: `string[]` or `string`
    - `names` (union string | string[])
      A list of indices (or index name patterns) to which the permissions in this entry apply.
    - `privileges` (union anyOf[])
      The index level privileges that owners of the role have on the specified indices.
      Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `create_view`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `delete_view`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `manage_view`, `monitor`, `none`, `read`, `read_cross_cluster`, `read_view_metadata`, `view_index_metadata`, `write`
    - `query` (union oneOf)
      A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
      - **string**
      - **[Query](https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
        An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
      - **RoleTemplateQuery**
        - `template` (object)
          When you create a role, you can specify a query that defines the document level security permissions. You can optionally
use Mustache templates in the role query to insert the username of the current authenticated user into the role.
Like other places in Elasticsearch that support templating or scripting, you can specify inline, stored, or file-based
templates and define custom parameters. You access the details for the current authenticated user through the _user parameter.
          - `source` (union oneOf)
            - **string**
            - **[Query](https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
              An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
          - `id` (string)
            The `id` for a stored script.
          - `params` (map string to object)
            Specifies any named parameters that are passed into the script as variables.
Use parameters instead of hard-coded values to decrease compile time.
          - `lang` (union anyOf · default: painless)
            Specifies the language the script is written in.

Supported values include:
  - `painless`: Painless scripting language, purpose-built for Elasticsearch.
  - `expression`: Lucene’s expressions language, compiles a JavaScript expression to bytecode.
  - `mustache`: Mustache templated, used for templates.
  - `java`: Expert Java API
            Values: `painless`, `expression`, `mustache`, `java`
          - `options` (map string to string)
    - `allow_restricted_indices` (boolean · default: false)
      Set to `true` if using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in the `names` list, Elasticsearch checks privileges against these indices regardless of the value set for `allow_restricted_indices`.
  - `remote_cluster` (object[])
    - `clusters` (union oneOf)
      A list of cluster aliases to which the permissions in this entry apply.
      One of: `string[]` or `string`
    - `privileges` (enum[])
      The cluster level privileges that owners of the role have on the remote cluster.
      Values: `monitor_enrich`, `monitor_stats`
  - `metadata` (object)
  - `description` (string)
  - `run_as` (string[])
  - `transient_metadata` (map string to object)
  - `applications` (object[])
    - `application` (string)
      The name of the application to which this entry applies.
    - `privileges` (string[])
      A list of strings, where each element is the name of an application privilege or action.
    - `resources` (string[])
      A list resources to which the privileges are applied.
  - `role_templates` (object[])
    - `format` (enum)
      Values: `string`, `json`
    - `template` (string)
  - `global` (object)
    - `application` (object)
      - `manage` (object)
        The applications for which application privileges can be managed.
Absent when the `application` section is present but grants no privileges.
        - `applications` (string[])
    - `profile` (object)
      A privilege that grants the ability to write the `data` and `access` sections of user profiles for the specified applications.
      - `write` (object)
        The applications for which user profile data can be written.
Absent when the `profile` section is present but grants no privileges.
        - `applications` (string[])
    - `role` (object)
      A privilege that grants the ability to manage roles that are scoped to the specified indices.
      - `manage` (object)
        The index-scoped role management privileges.
Absent when the `role` section is present but grants no privileges.
        - `indices` (object[])
          - `names` (string[])
            A list of indices (or index name patterns) that the owners of the role can manage roles for.
          - `privileges` (string[])
            The index privileges that the managed roles are allowed to grant on the specified indices.
    - `data_source` (object[])
      A list of data source privilege entries, used to grant access to ES|QL data sources.
      - `names` (string[])
        A list of data source names or wildcard patterns to which the permissions in this entry apply.
      - `privileges` (union anyOf[])
        The data source privileges that owners of the role have for the specified data sources.

Supported values include:
  - `create`: Grants privilege to create a data source with a matching name.
  - `delete`: Grants privilege to delete a data source with a matching name.
  - `read_metadata`: Grants privilege to read a data source's metadata.
  - `read`: Grants privilege to attach a dataset to a data source with a matching name.
  - `manage`: Grants all data source privileges, including `create`, `delete`, `read`, and `read_metadata`.
        Values: `create`, `delete`, `read_metadata`, `read`, `manage`
## Code examples

#### Console

```console
GET /_security/role/my_admin_role
```

#### JavaScript

```javascript
const response = await client.security.getRole({
  name: "my_admin_role",
});
```

#### Python

```python
resp = client.security.get_role(
    name="my_admin_role",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_security/role/my_admin_role" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().getRole(g -> g
    .name("my_admin_role")
);
```

#### C#

```c#
var response = await client.Security
    .GetRoleAsync(d1 => d1
        .Name(new[] { "my_admin_role" })
    );
```

#### PHP

```php
$resp = $client->security()->getRole([
    "name" => "my_admin_role",
]);
```

#### Ruby

```ruby
response = client.security.get_role(
  name: "my_admin_role"
)
```

## Response examples

#### Security get role response example1

`application/json`

A successful response from `GET /_security/role/my_admin_role`. The response contains information about the `my_admin_role` role in the native realm.

```json
{
  "my_admin_role": {
    "description": "Grants full access to all management features within the cluster.",
    "cluster" : [ "all" ],
    "indices" : [
      {
        "names" : [ "index1", "index2" ],
        "privileges" : [ "all" ],
        "allow_restricted_indices" : false,
        "field_security" : {
          "grant" : [ "title", "body" ]}
      }
    ],
    "applications" : [ ],
    "run_as" : [ "other_user" ],
    "metadata" : {
      "version" : 1
    },
    "transient_metadata": {
      "enabled": true
    }
  }
}
```

