---
type: api
title: Get user privileges
description: Get the security privileges for the logged in user.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-get-user-privileges
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-get-user-privileges
products:
  - Elasticsearch
---

# Get user privileges

Availability: 6.5+

## Paths

- `GET` `/_security/user/_privileges`

- [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)

## Description

Get the security privileges for the logged in user.
All users can use this API, but only to determine their own privileges.
To check the privileges of other users, you must use the run as feature.
To check whether a user has a specific list of privileges, use the has privileges API.

## Response

`application/json`

- `applications` ([] ApplicationPrivileges)
  - `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.
- `cluster` ([] string)
- `remote_cluster` ([] RemoteClusterPrivileges)
  - `clusters` (string Names)
    A list of cluster aliases to which the permissions in this entry apply.
  - `privileges` ([] enum RemoteClusterPrivilege)
    The cluster level privileges that owners of the role have on the remote cluster.
    Values: `monitor_enrich`, `monitor_stats`
- `global` ([] GlobalPrivilege)
  - `application` ({} ApplicationGlobalUserPrivileges)
    - `manage` ({} ManageUserPrivileges)
      - `applications` ([] string)
- `indices` ([] UserIndicesPrivileges)
  - `field_security` ([] FieldSecurity)
    The document fields that the owners of the role have read access to.
    - `except` (string Fields)
    - `grant` (string Fields)
  - `names` ([] string IndexName)
    A list of indices (or index name patterns) to which the permissions in this entry apply.
  - `privileges` ([] union IndexPrivilege)
    The index level privileges that owners of the role have on the specified indices.
    Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `monitor`, `none`, `read`, `read_cross_cluster`, `view_index_metadata`, `write`
  - `query` ([] union IndicesPrivilegesQuery)
    Search queries that define the documents the user has access to. A document within the specified indices must match these queries for it to be accessible by the owners of the role.
    - **string**
    - **[QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/types/_types-query_dsl-querycontainer)**
      An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
    - **RoleTemplateQuery**
      - `template` ({} RoleTemplateScript)
        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` (RoleTemplateInlineQuery)
        - `id` (string Id)
          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` (ScriptLanguage · 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)
    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` ([] RemoteUserIndicesPrivileges)
  - `clusters` ([] string)
  - `field_security` ([] FieldSecurity)
    The document fields that the owners of the role have read access to.
    - `except` (string Fields)
    - `grant` (string Fields)
  - `names` ([] string IndexName)
    A list of indices (or index name patterns) to which the permissions in this entry apply.
  - `privileges` ([] union IndexPrivilege)
    The index level privileges that owners of the role have on the specified indices.
    Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `monitor`, `none`, `read`, `read_cross_cluster`, `view_index_metadata`, `write`
  - `query` ([] union IndicesPrivilegesQuery)
    Search queries that define the documents the user has access to. A document within the specified indices must match these queries for it to be accessible by the owners of the role.
    - **string**
    - **[QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/types/_types-query_dsl-querycontainer)**
      An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
    - **RoleTemplateQuery**
      - `template` ({} RoleTemplateScript)
        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` (RoleTemplateInlineQuery)
        - `id` (string Id)
          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` (ScriptLanguage · 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)
    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`.
- `run_as` ([] string)
## Code Examples

#### Console

```console
GET /_security/user/_privileges
```

#### JavaScript

```javascript
const response = await client.security.getUserPrivileges();
```

#### Python

```python
resp = client.security.get_user_privileges()
```

#### curl

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

#### Java

```java
client.security().getUserPrivileges(g -> g);
```

#### C#

```c#
var response = await client.Security.GetUserPrivilegesAsync();
```

#### PHP

```php
$resp = $client->security()->getUserPrivileges();
```

#### Ruby

```ruby
response = client.security.get_user_privileges
```

## Response Examples

#### Security get user privileges response example1

A successful response from `GET /_security/user/_privileges`.

```json
{
  "cluster" : [
    "all"
  ],
  "global" : [ ],
  "indices" : [
    {
      "names" : [
        "*"
      ],
      "privileges" : [
        "all"
      ],
      "allow_restricted_indices" : true
    }
  ],
  "applications" : [
    {
      "application" : "*",
      "privileges" : [
        "*"
      ],
      "resources" : [
        "*"
      ]
    }
  ],
  "run_as" : [
    "*"
  ]
}
```

