Bulk delete roles API
Bulk deletes roles in the native realm.
Request
DELETE /_security/role/
Prerequisites
- To use this API, you must have at least the
manage_securitycluster privilege.
Description
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management. The bulk delete roles API cannot delete roles that are defined in roles files.
Path parameters
-
refresh - Optional setting of the refresh policy for the write request. Defaults to Immediate.
Request body
The following parameters can be specified in the body of a DELETE request and pertain to deleting a set of roles:
-
names - (list) A list of role names to delete.
Examples
The following example deletes a my_admin_role and my_user_role roles:
resp = client.security.bulk_delete_role(
names=[
"my_admin_role",
"my_user_role"
],
)
print(resp) const response = await client.security.bulkDeleteRole({
names: ["my_admin_role", "my_user_role"],
});
console.log(response); DELETE /_security/role
{
"names": ["my_admin_role", "my_user_role"]
} If the roles are successfully deleted, the request returns:
{
"deleted": [
"my_admin_role",
"my_user_role"
]
} If a role cannot be found, the not found roles are grouped under not_found:
resp = client.security.bulk_delete_role(
names=[
"my_admin_role",
"not_an_existing_role"
],
)
print(resp) const response = await client.security.bulkDeleteRole({
names: ["my_admin_role", "not_an_existing_role"],
});
console.log(response); DELETE /_security/role
{
"names": ["my_admin_role", "not_an_existing_role"]
} {
"deleted": [
"my_admin_role"
],
"not_found": [
"not_an_existing_role"
]
} If a request fails or is invalid, the errors are grouped under errors:
resp = client.security.bulk_delete_role(
names=[
"my_admin_role",
"superuser"
],
)
print(resp) const response = await client.security.bulkDeleteRole({
names: ["my_admin_role", "superuser"],
});
console.log(response); DELETE /_security/role
{
"names": ["my_admin_role", "superuser"]
} {
"deleted": [
"my_admin_role"
],
"errors": {
"count": 1,
"details": {
"superuser": {
"type": "illegal_argument_exception",
"reason": "role [superuser] is reserved and cannot be deleted"
}
}
}
}
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/security-api-bulk-delete-role.html