Skip to content

Commit 6ab6ca3

Browse files
Add RandomSampler aggregation (#1595) (#1800)
(cherry picked from commit 380b63b) Co-authored-by: Hüseyin Emre Armağan <[email protected]>
1 parent a950392 commit 6ab6ca3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

elasticsearch_dsl/aggs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ class DiversifiedSampler(Bucket):
278278
name = "diversified_sampler"
279279

280280

281+
class RandomSampler(Bucket):
282+
name = "random_sampler"
283+
284+
281285
class Composite(Bucket):
282286
name = "composite"
283287
_param_defs = {

tests/test_aggs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,22 @@ def test_normalize_aggregation():
383383
assert {
384384
"normalize": {"buckets_path": "normalized", "method": "percent_of_sum"}
385385
} == a.to_dict()
386+
387+
388+
def test_random_sampler_aggregation():
389+
a = aggs.RandomSampler(probability=0.1).metric(
390+
"price_percentiles",
391+
"percentiles",
392+
field="price",
393+
)
394+
395+
assert {
396+
"random_sampler": {
397+
"probability": 0.1,
398+
},
399+
"aggs": {
400+
"price_percentiles": {
401+
"percentiles": {"field": "price"},
402+
},
403+
},
404+
} == a.to_dict()

0 commit comments

Comments
 (0)