From 211f99e62823642c369ea9634be344eb31dd658e Mon Sep 17 00:00:00 2001 From: Telomeraz Date: Sat, 21 May 2022 15:11:46 +0300 Subject: [PATCH] Add IPPrefix aggregation --- elasticsearch_dsl/aggs.py | 4 ++++ tests/test_aggs.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/elasticsearch_dsl/aggs.py b/elasticsearch_dsl/aggs.py index 962cfc35..d9412e26 100644 --- a/elasticsearch_dsl/aggs.py +++ b/elasticsearch_dsl/aggs.py @@ -232,6 +232,10 @@ class IPRange(Bucket): name = "ip_range" +class IPPrefix(Bucket): + name = "ip_prefix" + + class Missing(Bucket): name = "missing" diff --git a/tests/test_aggs.py b/tests/test_aggs.py index e908cc00..936c2bcd 100644 --- a/tests/test_aggs.py +++ b/tests/test_aggs.py @@ -300,6 +300,30 @@ def test_variable_width_histogram_aggregation(): assert {"variable_width_histogram": {"buckets": 2, "field": "price"}} == a.to_dict() +def test_ip_prefix_aggregation(): + a = aggs.IPPrefix(**{"field": "ipv4", "prefix_length": 24}) + + assert {"ip_prefix": {"field": "ipv4", "prefix_length": 24}} == a.to_dict() + + +def test_ip_prefix_aggregation_extra(): + a = aggs.IPPrefix( + **{ + "field": "ipv6", + "prefix_length": 64, + "is_ipv6": True, + } + ) + + assert { + "ip_prefix": { + "field": "ipv6", + "prefix_length": 64, + "is_ipv6": True, + }, + } == a.to_dict() + + def test_multi_terms_aggregation(): a = aggs.MultiTerms(terms=[{"field": "tags"}, {"field": "author.row"}]) assert {