Skip to content

Commit

Permalink
Add RandomSampler aggregation (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
Telomeraz committed Apr 15, 2024
1 parent 619daa1 commit 380b63b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions elasticsearch_dsl/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ class DiversifiedSampler(Bucket):
name = "diversified_sampler"


class RandomSampler(Bucket):
name = "random_sampler"


class Composite(Bucket):
name = "composite"
_param_defs = {
Expand Down
19 changes: 19 additions & 0 deletions tests/test_aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,22 @@ def test_normalize_aggregation():
assert {
"normalize": {"buckets_path": "normalized", "method": "percent_of_sum"}
} == a.to_dict()


def test_random_sampler_aggregation():
a = aggs.RandomSampler(probability=0.1).metric(
"price_percentiles",
"percentiles",
field="price",
)

assert {
"random_sampler": {
"probability": 0.1,
},
"aggs": {
"price_percentiles": {
"percentiles": {"field": "price"},
},
},
} == a.to_dict()

0 comments on commit 380b63b

Please sign in to comment.