File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff 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 , {})
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments