Skip to content

add documentation for Rule lifecycle API for workload group #9836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
layout: default
title: Rule lifecycle API for workload group
nav_order: 20
parent: Workload management
grand_parent: Availability and recovery
---

# Rule lifecycle API for workload group

The Rule Lifecycle API for the `workload_group` feature type enables users to define, update, retrieve, and delete rules that automatically assign workload group IDs to incoming queries.
When a query matches the attributes defined in a rule, OpenSearch automatically tags it with the corresponding workload group ID. This removes the need for clients to explicitly include the workload group in each request.

For the detailed description regarding the rule-based autotagging API usage, please refer to [this page]({{site.url}}{{site.baseurl}}/tuning-your-cluster/availability-and-recovery/rule-based-autotagging/rule-lifecycle-api/).

Check failure on line 14 in _tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: autotagging. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: autotagging. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md", "range": {"start": {"line": 14, "column": 55}}}, "severity": "ERROR"}

Check warning on line 14 in _tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Please] Using 'please' is unnecessary. Remove. Raw Output: {"message": "[OpenSearch.Please] Using 'please' is unnecessary. Remove.", "location": {"path": "_tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md", "range": {"start": {"line": 14, "column": 78}}}, "severity": "WARNING"}

## Supporting attributes

For the `workload_group` feature type, the following tables shows the supporting attributes

| Attribute | Data type | Description |
|:----------------|:----------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `index_pattern` | List | A list of string used to match the target indices of incoming queries. Each string can be an exact index name or a prefix ending with * to support wildcard matching (e.g., "logs*") |

Check failure on line 22 in _tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.SubstitutionsError] Use 'indexes' instead of 'indices'. Raw Output: {"message": "[OpenSearch.SubstitutionsError] Use 'indexes' instead of 'indices'.", "location": {"path": "_tuning-your-cluster/availability-and-recovery/workload-management/wlm-rule-lifecycle-api.md", "range": {"start": {"line": 22, "column": 75}}}, "severity": "ERROR"}


## Example requests

The following example demonstrates how to use the Rule Lifecycle API to create a rule for the `workload_group` feature type.

### Create a rule

The following request creates a rule that assigns a `workload_group` value based on matching `index_pattern` attributes:

```json
PUT _rules/workload_group
{
"description": "description for rule",
"index_pattern": ["log*", "event*"],
"workload_group": "EITBzjFkQ6CA-semNWGtRQ"
}
```
{% include copy-curl.html %}

### Update a rule

The following request updates a rule with ID `0A6RULxkQ9yLqn4r8LPrIg`:

```json
PUT _rules/workload_group/0A6RULxkQ9yLqn4r8LPrIg
{
"description": "updated_description for rule",
"index_pattern": ["log*"],
"workload_group": "EITBzjFkQ6CA-semNWGtRQ"
}
```
{% include copy-curl.html %}

You can't change the `feature_type`. Fields that are not updated can be omitted.
{: .note }

### Get a rule

The following request retrieves a rule by ID under the feature type `workload_group`:

```json
GET /_rules/workload_group/{_id}
```
{% include copy-curl.html %}

The following request retrieves all rules for the feature type `workload_group`:

```json
GET /_rules/workload_group
```
{% include copy-curl.html %}

The following request returns all rules of the feature type `workload_group` that contain the attribute `index_pattern` with values `a` or `b`:

```json
GET /_rules/workload_group?index_pattern=a,b
```
{% include copy-curl.html %}

If a `GET` request returns more results than can be included in a single response, the system paginates the results and includes a `search_after` field in the response.
To retrieve the next page, send another request to the same endpoint using the same filters and include the `search_after` value from the previous response as a query parameter.

The following example continues the search for all rules of the `workload_group` feature type where the `index_pattern` attribute contains the values `a` or `b`:

```json
"GET /_rules/workload_group?index_pattern=a,b&search_after=z1MJApUB0zgMcDmz-UQq"
```
{% include copy-curl.html %}

## Example responses

<details open markdown="block">
<summary>
Response: Create or update rule
</summary>
{: .text-delta }

```json
{
"_id": "wi6VApYBoX5wstmtU_8l",
"description": "description for rule",
"index_pattern": ["log*", "event*"],
"workload_group": "EITBzjFkQ6CA-semNWGtRQ",
"updated_at": "2025-04-04T20:54:22.406Z"
}
```

</details>


<details markdown="block">
<summary>
Response: Get rules
</summary>
{: .text-delta }

```json
{
"rules": [
{
"_id": "z1MJApUB0zgMcDmz-UQq",
"description": "Rule for tagging workload_group_id to index123",
"index_pattern": ["index123"],
"workload_group": "workload_group_id",
"updated_at": "2025-02-14T01:19:22.589Z"
},
...
],
"search_after": ["z1MJApUB0zgMcDmz-UQq"]
}
```

If the `search_after` field is present in the response, more results are available.
To retrieve the next page, include the `search_after` value in the next `GET` request as a query parameter, such as `GET /_rules/{feature_type}?search_after=z1MJApUB0zgMcDmz-UQq`.

</details>
Loading