---
type: api
title: Update a filter
description: Updates the description of a filter, adds items, or removes items from the list.
url: https://www.elastic.co/docs/api/doc/elasticsearch-serverless/operation/operation-ml-update-filter
resource: https://www.elastic.co/docs/api/doc/elasticsearch-serverless/operation/operation-ml-update-filter
products:
  - Elasticsearch Serverless
---

# Update a filter

Authentication: required

## Paths

- `POST` `/_ml/filters/{filter_id}/_update`

#### Path parameters

- `filter_id` (string) — required
  A string that uniquely identifies a filter.

## Description

Updates the description of a filter, adds items, or removes items from the list.

## Required privileges

- Cluster privileges: `manage_ml`

## Request body

`application/json`

- `add_items` (string[]) — optional
  The items to add to the filter.
- `description` (string) — optional
  A description for the filter.
- `remove_items` (string[]) — optional
  The items to remove from the filter.

## Response

`application/json`

- `description` (string)
- `filter_id` (string)
- `items` (string[])
## Code examples

#### Console

```console
POST _ml/filters/safe_domains/_update
{
  "description": "Updated list of domains",
  "add_items": ["*.myorg.com"],
  "remove_items": ["wikipedia.org"]
}
```

#### JavaScript

```javascript
const response = await client.ml.updateFilter({
  filter_id: "safe_domains",
  description: "Updated list of domains",
  add_items: ["*.myorg.com"],
  remove_items: ["wikipedia.org"],
});
```

#### Python

```python
resp = client.ml.update_filter(
    filter_id="safe_domains",
    description="Updated list of domains",
    add_items=[
        "*.myorg.com"
    ],
    remove_items=[
        "wikipedia.org"
    ],
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/filters/safe_domains/_update" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Updated list of domains",
    "add_items": [
      "*.myorg.com"
    ],
    "remove_items": [
      "wikipedia.org"
    ]
  }'
```

#### Java

```java
client.ml().updateFilter(u -> u
    .addItems("*.myorg.com")
    .description("Updated list of domains")
    .filterId("safe_domains")
    .removeItems("wikipedia.org")
);
```

#### C#

```c#
var response = await client.MachineLearning
    .UpdateFilterAsync(filterId: "safe_domains", d1 => d1
        .AddItems("*.myorg.com")
        .Description("Updated list of domains")
        .RemoveItems("wikipedia.org")
    );
```

#### PHP

```php
$resp = $client->ml()->updateFilter([
    "filter_id" => "safe_domains",
    "body" => [
        "description" => "Updated list of domains",
        "add_items" => array(
            "*.myorg.com",
        ),
        "remove_items" => array(
            "wikipedia.org",
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.ml.update_filter(
  filter_id: "safe_domains",
  body: {
    "description": "Updated list of domains",
    "add_items": [
      "*.myorg.com"
    ],
    "remove_items": [
      "wikipedia.org"
    ]
  }
)
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "description": "string",
  "filter_id": "string",
  "items": [
    "string"
  ]
}
```

