Skip to content

[Transform] Delete API fails when destination index writes to alias #121913

@prwhelan

Description

@prwhelan

When a transform writes to an alias, calling the Delete API with delete_dest_index throws an IllegalArgumentException:

BadRequestError: BadRequestError(400, 'illegal_argument_exception', 'The provided expression [dice-rolls-write] matches an alias, specify the corresponding concrete indices instead.')
from elasticsearch import Elasticsearch
import os
from datetime import datetime, timezone
import numpy as np
import time

# Initialize Client
es_url = os.getenv("ES_URL", "http://localhost:9200")
es_user = os.getenv("ES_USERNAME", "elastic")
es_password = os.getenv("ES_PASSWORD", "password")

es = Elasticsearch(
    hosts=es_url, basic_auth=(es_user, es_password), verify_certs=False, ssl_show_warn=False
)

es.cluster.put_settings(
    flat_settings="true",
    body={"transient": {"logger.org.elasticsearch.xpack.transform.transforms": "debug"}},
)

source_index="random-dice"
dest_index="dice-rolls"
dest_index_alias="dice-rolls-write"
transform_id="dice-rolls"

print("Loading first value into index")
print(es.index(index=source_index, document={
    'value': np.random.randint(1,21),
    'time': datetime.now(timezone.utc)
}))

print("Creating Index & Alias")
print(es.indices.create(index=dest_index))
print(es.indices.update_aliases(
    actions=[
        {
            "add": {
                "index": dest_index,
                "alias": dest_index_alias
            }
        }
    ],
))

print("Creating Transform")
es.transform.put_transform(
    transform_id=transform_id,
    source={
        "index": source_index
    },
    dest={
        "index": dest_index_alias
    },
    pivot={
        "group_by": {
            "dice value": {
                "terms": {
                    "field": "value",
                    "missing_bucket": True
                }
            }
        },
        "aggregations": {
            "occurrences": {
                "value_count": {
                    "field": "value"
                }
            }
        }
    },
    frequency= "5s",
    sync= {
        "time": {
            "field": "time",
            "delay": "5s"
        }
    }
)

print("Starting Transform")
print(es.transform.start_transform(
    transform_id=transform_id
))

print("Stopping Transform")
print(es.transform.stop_transform(
    transform_id=transform_id,
    wait_for_completion=True
))

print("Deleting Transform")
print(es.transform.delete_transform(
    transform_id=transform_id,
    delete_dest_index=True
))

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions