Skip to content

Commit 9c56658

Browse files
committed
add _aggregation_name
1 parent 64b7530 commit 9c56658

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

awswrangler/opensearch/_read.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _search_response_to_documents(
4747
hits = response.get("hits", {}).get("hits", [])
4848
if not hits and aggregations:
4949
hits = [
50-
aggregation_hit
50+
dict(aggregation_hit, _aggregation_name=aggregation_name)
5151
for aggregation_name in aggregations
5252
for aggregation_hit in response.get("aggregations", {})
5353
.get(aggregation_name, {})

tests/unit/test_opensearch.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,19 @@ def test_search_aggregation(client):
442442
df = wr.opensearch.search(
443443
client,
444444
index=index,
445-
search_body={"aggregations": {"top_hits_inspections": {"top_hits": {"size": 2}}}},
445+
search_body={
446+
"aggregations": {
447+
"latest_inspections": {"top_hits": {"sort": [{"inspection_date": {"order": "asc"}}], "size": 1}},
448+
"lowest_inspection_score": {
449+
"top_hits": {"sort": [{"inspection_score": {"order": "asc"}}], "size": 1}
450+
},
451+
}
452+
},
446453
filter_path=["aggregations"],
447454
)
448455
assert df.shape[0] == 2
456+
assert len(df.loc[df["_aggregation_name"] == "latest_inspections"]) == 1
457+
assert len(df.loc[df["_aggregation_name"] == "lowest_inspection_score"]) == 1
449458
finally:
450459
wr.opensearch.delete_index(client, index)
451460

0 commit comments

Comments
 (0)