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

# Get role mappings


Availability: Generally available since 5.5

## Paths

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

#### Path parameters

- `name` (union string | string[]) — optional, leave it out to use `/_security/role_mapping`
  The distinct name that identifies the role mapping. The name is used solely as an identifier to facilitate interaction via the API; it does not affect the behavior of the mapping in any way. You can specify multiple mapping names as a comma-separated list. If you do not specify this parameter, the API returns information about all role mappings.

## Description

Role mappings define which roles are assigned to each user.
The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files.
The get role mappings API cannot retrieve role mappings that are defined in role mapping files.

[Read the reference documentation](https://www.elastic.co/guide/en/elasticsearch/reference/8.19/mapping-roles.html)

## Required authorization

- Cluster privileges: `manage_security`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Response

`application/json`

- `<string>` (object)
  - `enabled` (boolean)
  - `metadata` (object)
  - `roles` (string[])
  - `role_templates` (object[])
    - `format` (enum)
      Values: `string`, `json`
    - `template` (string)
  - `rules` (object)
    - `any` (object[]) — recursive
      Same fields as `rules` in `<string>`
    - `all` (object[]) — recursive
      Same fields as `rules` in `<string>`
    - `field` (object)
      - `username` (string)
      - `dn` (string)
      - `groups` (string)
    - `except` (object) — recursive
      Same fields as `rules` in `<string>`
## Code examples

#### Console

```console
GET /_security/role_mapping/mapping1
```

#### JavaScript

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

#### Python

```python
resp = client.security.get_role_mapping(
    name="mapping1",
)
```

#### curl

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

#### Java

```java
client.security().getRoleMapping(g -> g
    .name("mapping1")
);
```

#### C#

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

#### PHP

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

#### Ruby

```ruby
response = client.security.get_role_mapping(
  name: "mapping1"
)
```

## Response examples

#### Security get role mapping response example1

A successful response from `GET /_security/role_mapping/mapping1`.

```json
{
  "mapping1": {
    "enabled": true,
    "roles": [
      "user"
    ],
    "rules": {
      "field": {
        "username": "*"
      }
    },
    "metadata": {}
  }
}
```

