Skip to content

Commit 49b9c92

Browse files
Telomerazgithub-actions[bot]
authored andcommitted
Add IPPrefix aggregation (#1593)
(cherry picked from commit f091a23)
1 parent e30129d commit 49b9c92

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

elasticsearch_dsl/aggs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ class IPRange(Bucket):
232232
name = "ip_range"
233233

234234

235+
class IPPrefix(Bucket):
236+
name = "ip_prefix"
237+
238+
235239
class Missing(Bucket):
236240
name = "missing"
237241

tests/test_aggs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,30 @@ def test_variable_width_histogram_aggregation():
300300
assert {"variable_width_histogram": {"buckets": 2, "field": "price"}} == a.to_dict()
301301

302302

303+
def test_ip_prefix_aggregation():
304+
a = aggs.IPPrefix(**{"field": "ipv4", "prefix_length": 24})
305+
306+
assert {"ip_prefix": {"field": "ipv4", "prefix_length": 24}} == a.to_dict()
307+
308+
309+
def test_ip_prefix_aggregation_extra():
310+
a = aggs.IPPrefix(
311+
**{
312+
"field": "ipv6",
313+
"prefix_length": 64,
314+
"is_ipv6": True,
315+
}
316+
)
317+
318+
assert {
319+
"ip_prefix": {
320+
"field": "ipv6",
321+
"prefix_length": 64,
322+
"is_ipv6": True,
323+
},
324+
} == a.to_dict()
325+
326+
303327
def test_multi_terms_aggregation():
304328
a = aggs.MultiTerms(terms=[{"field": "tags"}, {"field": "author.row"}])
305329
assert {

0 commit comments

Comments
 (0)