# Bulk delete role mappings

**URL:** <https://discuss.elastic.co/t/bulk-delete-role-mappings/227688>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [April 12, 2020, 5:34pm UTC](https://discuss.elastic.co/t/bulk-delete-role-mappings/227688 "2020-04-12T17:34:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumendra](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@soumendra](https://discuss.elastic.co/u/soumendra)\
**Post date:** [April 12, 2020, 5:34pm UTC](https://discuss.elastic.co/t/bulk-delete-role-mappings/227688/1 "2020-04-12T17:34:07Z")

</div>

I have role mapping created like the following:

```
PUT {{es_ip_port}}/_security/role_mapping/dummy_1
{
    "enabled": true,
    "roles": [
        "client_role",
        "kibana_dashboard_only_user"
    ],
    "rules": {
        "all": [
            {
                "field": {
                    "realm.name": "oidc1"
                }
            },
            {
                "field": {
                    "username": [
                        "dummy_user@dummy.com"
                    ]
                }
            }
        ]
    }
}

```

Similarly I have more role-mappings created with role\_mapping name `dummy_2`, `dummy_3`, etc.  
I want to delete all the role mappings starting with the name, `dummy_` like `dummy_*`. Is there any way to do it over DELETE API at one shot like below:

```
DELETE {{es_ip_port}}/_security/role_mapping/dummy_*

```

I do not want to delete the role mappings one by one. Is there any way? Please help.

---

<div class="post-metadata">

**Author:** ![soumendra](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@soumendra](https://discuss.elastic.co/u/soumendra)\
**Post date:** [April 19, 2020, 6:36pm UTC](https://discuss.elastic.co/t/bulk-delete-role-mappings/227688/2 "2020-04-19T18:36:43Z")

</div>

This is for any future visitor to this thread. There is not bulk delete role mapping option. I knew what was I doing so used `_delete_by_query` API call on the `.security-7` index. My sample API looks like below:

```
POST {{es_ip_port}}/.security-7/_delete_by_query?conflicts=proceed
{
    "query": {
        "match": {
            "roles": "<role mapping with the needed role to delete>"
        }
    }
}

```

Generally this option is not recommended. Please use it carefully.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 17, 2020, 6:36pm UTC](https://discuss.elastic.co/t/bulk-delete-role-mappings/227688/3 "2020-05-17T18:36:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
