Update aliases and delete indices atomically Generally available; Added in 1.3.0

POST /_aliases

Applies one or more actions in a single request:

  • Add a data stream or index to an alias.
  • Remove a data stream or index from an alias.
  • Delete an index in that same request, so the deletion and the alias changes are applied together.

For example, you can replace an index with an alias of the same name.

NOTE: Every remove_index action in the request runs first, before any add or remove actions, no matter where it sits in the actions array.

Required authorization

  • Index privileges: manage

Query parameters

  • master_timeout string

    Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.

    Default value is 30s.

  • timeout string

    Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

    Default value is 30s.

application/json

Body Required

  • actions array[object]

    Actions to perform.

    Hide actions attributes Show actions attributes object
    • add object

      Adds a data stream or index to an alias. If the alias doesn’t exist, the add action creates it.

      Hide add attributes Show add attributes object
      • alias string

        Alias for the action. Index alias names support date math.

      • aliases string | array[string]

        Aliases for the action. Index alias names support date math.

      • filter object

        Query used to limit documents the alias can access.

        External documentation
      • index string

        Data stream or index for the action. Supports wildcards (*). Wildcard patterns that match both data streams and indices return an error.

      • indices string | array[string]

        Data streams or indices for the action. Supports wildcards (*). Wildcard patterns that match both data streams and indices return an error.

      • index_routing string

        Value used to route indexing operations to a specific shard. If specified, this overwrites the routing value for indexing operations. Data stream aliases don’t support this parameter.

      • is_hidden boolean

        If true, the alias is hidden.

        Default value is false.

      • is_write_index boolean

        If true, sets the write index or data stream for the alias.

      • routing string

        Value used to route indexing and search operations to a specific shard. Data stream aliases don’t support this parameter.

      • search_routing string

        Value used to route search operations to a specific shard. If specified, this overwrites the routing value for search operations. Data stream aliases don’t support this parameter.

      • must_exist boolean

        If true, the alias must exist to perform the action.

        Default value is false.

    • remove object

      Removes a data stream or index from an alias.

      Hide remove attributes Show remove attributes object
      • alias string

        Alias for the action. Index alias names support date math.

      • aliases string | array[string]

        Aliases for the action. Index alias names support date math.

      • index string

        Data stream or index for the action. Supports wildcards (*).

      • indices string | array[string]

        Data streams or indices for the action. Supports wildcards (*).

      • must_exist boolean

        If true, the alias must exist to perform the action.

        Default value is false.

    • remove_index object

      Deletes an index. You cannot use this action on aliases or data streams.

      Hide remove_index attributes Show remove_index attributes object
      • index string

        Data stream or index for the action. Supports wildcards (*).

      • indices string | array[string]

        Data streams or indices for the action. Supports wildcards (*).

      • must_exist boolean

        If true, the alias must exist to perform the action.

        Default value is false.

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • acknowledged boolean Required

      For a successful response, this value is always true. On failure, an exception is returned instead.

    • errors boolean Required Generally available; Added in 8.14.0

      If true, one or more actions failed. The request still returns HTTP 200.

    • action_results array[object] Generally available; Added in 8.14.0

      Results for each action in the request. Returned only when errors is true.

      Hide action_results attributes Show action_results attributes object
      • action object Required

        The action this result describes.

        Hide action attributes Show action attributes object
        • indices array[string] Required

          Resolved data streams or indices for the action.

        • aliases array[string] Required

          Aliases for the action.

      • status number Required

        HTTP status for this action. 200 when the action succeeds.

      • error object

        Cause of the failure. Returned only when this action fails.

        Hide error attributes Show error attributes object
        • type string Required

          The type of error

        • reason
        • stack_trace string

          The server stack trace. Present only if the error_trace=true parameter was sent with the request.

        • root_cause array[object]

          Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

        • suppressed array[object]

          Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

POST /_aliases
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "logs-nginx.access-*",
        "alias": "logs"
      }
    }
  ]
}
resp = client.indices.update_aliases(
    actions=[
        {
            "add": {
                "index": "logs-nginx.access-*",
                "alias": "logs"
            }
        }
    ],
)
const response = await client.indices.updateAliases({
  actions: [
    {
      add: {
        index: "logs-nginx.access-*",
        alias: "logs",
      },
    },
  ],
});
response = client.indices.update_aliases(
  body: {
    "actions": [
      {
        "add": {
          "index": "logs-nginx.access-*",
          "alias": "logs"
        }
      }
    ]
  }
)
$resp = $client->indices()->updateAliases([
    "body" => [
        "actions" => array(
            [
                "add" => [
                    "index" => "logs-nginx.access-*",
                    "alias" => "logs",
                ],
            ],
        ),
    ],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"actions":[{"add":{"index":"logs-nginx.access-*","alias":"logs"}}]}' "$ELASTICSEARCH_URL/_aliases"
var response = await client.Indices
    .UpdateAliasesAsync(d1 => d1
        .Actions(d2 => d2
            .Add(d3 => d3
                .Alias("logs")
                .Index("logs-nginx.access-*")
            )
        )
    );
client.indices().updateAliases(u -> u
    .actions(a -> a
        .add(ad -> ad
            .alias("logs")
            .index("logs-nginx.access-prod")
        )
    )
);
Request examples
If the alias does not exist, it is created.
{
  "actions": [
    {
      "add": {
        "index": "logs-nginx.access-*",
        "alias": "logs"
      }
    }
  ]
}
{
  "actions": [
    {
      "remove": {
        "index": "logs-nginx.access-prod",
        "alias": "logs"
      }
    }
  ]
}
First, remove the index `my-index-1` (which has the alias `my-alias`) and then add the index `my-index-2` to the alias in a single request.
{
  "actions": [
    {
      "remove_index": {
        "index": "my-index-1"
      }
    },
    {
      "add": {
        "index": "my-index-2",
        "alias": "my-alias"
      }
    }
  ]
}
Response examples (200)
When using multiple actions, if some succeed and some fail, the API returns a list of per-action results. For example, if the alias `logs-non-existing` does not exist, the API returns a 404 error for the `remove` action.
{
  "acknowledged": true,
  "errors": true,
  "action_results": [
    {
      "action": {
        "type": "remove",
        "indices": [
          "logs-nginx.access-prod"
        ],
        "aliases": [
          "logs-non-existing"
        ]
      },
      "status": 404,
      "error": {
        "type": "aliases_not_found_exception",
        "reason": "aliases [logs-non-existing] missing",
        "resource.type": "aliases",
        "resource.id": "logs-non-existing"
      }
    },
    {
      "action": {
        "type": "add",
        "indices": [
          "logs-nginx.access-default"
        ],
        "aliases": [
          "logs-non-existing"
        ]
      },
      "status": 200
    }
  ]
}