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

# Get role mappings


Availability: 5.5+

## Paths

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

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `name` (union Name | [] Name) — 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.

## Required authorization

* Cluster privileges: `manage_security`

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

## Response

`application/json`

Type: `map string to RoleMapping`

## 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": {}
  }
}
```

