Skip to content
Merged
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
2 changes: 1 addition & 1 deletion elasticsearch_dsl/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __getitem__(self, agg_name: str) -> Agg[_R]:
# make sure we're not mutating a shared state - whenever accessing a
# bucket, return a shallow copy of it to be safe
if isinstance(agg, Bucket):
agg = A(agg.name, filter=None, **agg._params)
agg = A(agg.name, **agg._params)
# be sure to store the copy so any modifications to it will affect us
self._params["aggs"][agg_name] = agg

Expand Down
9 changes: 9 additions & 0 deletions tests/test_aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,12 @@ def test_top_metrics_aggregation() -> None:
assert {
"top_metrics": {"metrics": {"field": "m"}, "sort": {"s": "desc"}}
} == a.to_dict()


def test_bucket_agg_with_filter() -> None:
b = aggs.Filter(query.Terms(something=[1, 2, 3]))

a = aggs.Terms(field="some_field", size=100)
a.bucket("b", b)

assert a.aggs["b"] == a["b"] # a['b'] threw exception before patch #1902
Loading