Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Unreleased
----------

* Fix ``pandas_to_eland`` failing to append to an aliased index (`#829 <https://github.com/elastic/eland/pull/829>`_)

9.2.0 (2025-10-30)
------------------

Expand Down
20 changes: 12 additions & 8 deletions eland/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,18 @@ def pandas_to_eland(
es_client.indices.create(index=es_dest_index, mappings=mapping["mappings"])

elif es_if_exists == "append" and es_verify_mapping_compatibility:
dest_mapping = es_client.indices.get_mapping(index=es_dest_index)[
es_dest_index
]
verify_mapping_compatibility(
ed_mapping=mapping,
es_mapping=dest_mapping,
es_type_overrides=es_type_overrides,
)
# get_mapping keys its response by concrete index name, which differs
# from es_dest_index when it is an alias. Verify against every index
# the name resolves to rather than assuming the response is keyed by
# es_dest_index (which raised KeyError for an alias, see #747).
for dest_mapping in es_client.indices.get_mapping(
index=es_dest_index
).values():
verify_mapping_compatibility(
ed_mapping=mapping,
es_mapping=dest_mapping,
es_type_overrides=es_type_overrides,
)
else:
es_client.indices.create(index=es_dest_index, mappings=mapping["mappings"])

Expand Down
28 changes: 28 additions & 0 deletions tests/etl/test_pandas_to_eland.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ def test_es_if_exists_append(self):
pd_df3 = pd_df._append(pd_df2)
assert_pandas_eland_frame_equal(pd_df3, df2)

def test_es_if_exists_append_to_alias(self):
# Regression for #747: appending through an alias used to fail with
# KeyError, because get_mapping keys its response by the concrete index
# name rather than by the alias passed as es_dest_index.
pandas_to_eland(
pd_df,
es_client=ES_TEST_CLIENT,
es_dest_index="test-index",
es_refresh=True,
)
ES_TEST_CLIENT.indices.put_alias(index="test-index", name="test-alias")

try:
df = pandas_to_eland(
pd_df,
es_client=ES_TEST_CLIENT,
es_dest_index="test-alias",
es_if_exists="append",
es_refresh=True,
)

# Both writes landed in the aliased index.
assert df.shape == (6, 4)
finally:
ES_TEST_CLIENT.indices.delete_alias(
index="test-index", name="test-alias", ignore=404
)

def test_es_if_exists_append_mapping_mismatch_schema_enforcement(self):
df1 = pandas_to_eland(
pd_df,
Expand Down