Repository: elastic/elasticsearch-dsl-py

Issue:
Add support for "random_sampler" bucket aggregation
`elasticsearch_dsl/aggs.py` is missing "random_sampler" bucket aggregation which is introduced in [v8.2.0](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/release-notes-8.2.0.html#feature-8.2.0). [Random sampler aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-random-sampler-aggregation.html)

Discussion:

Patch:
diff --git a/elasticsearch_dsl/aggs.py b/elasticsearch_dsl/aggs.py
index 11612fb..962cfc3 100644
--- a/elasticsearch_dsl/aggs.py
+++ b/elasticsearch_dsl/aggs.py
@@ -278,6 +278,10 @@ class DiversifiedSampler(Bucket):
     name = "diversified_sampler"
 
 
+class RandomSampler(Bucket):
+    name = "random_sampler"
+
+
 class Composite(Bucket):
     name = "composite"
     _param_defs = {


Test patch:
diff --git a/tests/test_aggs.py b/tests/test_aggs.py
index 16c2ad5..e908cc0 100644
--- a/tests/test_aggs.py
+++ b/tests/test_aggs.py
@@ -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()