All methods and paths for this operation:
Get roles in a paginated manner. The role management APIs are generally the preferred way to manage roles, rather than using file-based role management. The query roles API does not retrieve roles that are defined in roles files, nor built-in ones. You can optionally filter the results with a query. Also, the results can be paginated and sorted.
read_securityA query to filter which roles to return.
If the query parameter is missing, it is equivalent to a match_all query.
The query supports a subset of query types, including match_all, bool, term, terms, match,
ids, prefix, wildcard, exists, range, and simple_query_string.
You can query the following information associated with roles: name, description, metadata,
applications.application, applications.privileges, and applications.resources.
The starting document offset.
It must not be negative.
By default, you cannot page through more than 10,000 hits using the from and size parameters.
To page through more hits, use the search_after parameter.
Default value is 0.
The sort definition.
You can sort on username, roles, or enabled.
In addition, sort can also be applied to the _doc field to sort by index order.
The number of hits to return.
It must not be negative.
By default, you cannot page through more than 10,000 hits using the from and size parameters.
To page through more hits, use the search_after parameter.
Default value is 10.
The search after definition.
POST /_security/_query/role
{
"sort": ["name"]
}
resp = client.security.query_role(
sort=[
"name"
],
)
const response = await client.security.queryRole({
sort: ["name"],
});
response = client.security.query_role(
body: {
"sort": [
"name"
]
}
)
$resp = $client->security()->queryRole([
"body" => [
"sort" => array(
"name",
),
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"sort":["name"]}' "$ELASTICSEARCH_URL/_security/_query/role"
{
"sort": ["name"]
}
{
"query": {
"match": {
"description": {
"query": "user access"
}
}
},
"size": 1
}
{
"total": 2,
"count": 2,
"roles": [
{
"name" : "my_admin_role",
"cluster" : [
"all"
],
"indices" : [
{
"names" : [
"index1",
"index2"
],
"privileges" : [
"all"
],
"field_security" : {
"grant" : [
"title",
"body"
]
},
"allow_restricted_indices" : false
}
],
"applications" : [ ],
"run_as" : [
"other_user"
],
"metadata" : {
"version" : 1
},
"transient_metadata" : {
"enabled" : true
},
"description" : "Grants full access to all management features within the cluster.",
"_sort" : [
"my_admin_role"
]
},
{
"name" : "my_user_role",
"cluster" : [ ],
"indices" : [
{
"names" : [
"index1",
"index2"
],
"privileges" : [
"all"
],
"field_security" : {
"grant" : [
"title",
"body"
]
},
"allow_restricted_indices" : false
}
],
"applications" : [ ],
"run_as" : [ ],
"metadata" : {
"version" : 1
},
"transient_metadata" : {
"enabled" : true
},
"description" : "Grants user access to some indicies.",
"_sort" : [
"my_user_role"
]
}
]
}
{
"total": 2,
"count": 1,
"roles": [
{
"name" : "my_user_role",
"cluster" : [ ],
"indices" : [
{
"names" : [
"index1",
"index2"
],
"privileges" : [
"all"
],
"field_security" : {
"grant" : [
"title",
"body"
]
},
"allow_restricted_indices" : false
}
],
"applications" : [ ],
"run_as" : [ ],
"metadata" : {
"version" : 1
},
"transient_metadata" : {
"enabled" : true
},
"description" : "Grants user access to some indicies."
}
]
}