From c05640207a0bfe5e5e167a241792ab0dc045912b Mon Sep 17 00:00:00 2001 From: vismaytiwari Date: Mon, 29 Jun 2026 22:37:05 +0530 Subject: [PATCH 1/2] Fix pandas_to_eland append to an aliased index When es_dest_index is an alias, indices.get_mapping keys its response by the concrete index name, so the previous response[es_dest_index] lookup raised KeyError and made appends to an aliased index fail. Verify mapping compatibility against every index the name resolves to instead, which also covers an alias spanning multiple indices. Closes #747 --- eland/etl.py | 20 ++++++++++++-------- tests/etl/test_pandas_to_eland.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/eland/etl.py b/eland/etl.py index 381ac756..15bc0c77 100644 --- a/eland/etl.py +++ b/eland/etl.py @@ -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"]) diff --git a/tests/etl/test_pandas_to_eland.py b/tests/etl/test_pandas_to_eland.py index 793bfa81..2ffcfd9b 100644 --- a/tests/etl/test_pandas_to_eland.py +++ b/tests/etl/test_pandas_to_eland.py @@ -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, From 1ba610012cdf42014d3ae348d1e003fd9e2588f8 Mon Sep 17 00:00:00 2001 From: vismaytiwari Date: Mon, 29 Jun 2026 22:38:07 +0530 Subject: [PATCH 2/2] Add changelog entry for #829 --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9ea31f37..5a796b7c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +Unreleased +---------- + +* Fix ``pandas_to_eland`` failing to append to an aliased index (`#829 `_) + 9.2.0 (2025-10-30) ------------------