From 164a62c79fd621d3272aec9acd40d38b5774bc57 Mon Sep 17 00:00:00 2001 From: Jonakemon Date: Wed, 19 Jan 2022 00:37:22 +0100 Subject: [PATCH] Add support for adjacency matrix --- elasticsearch_dsl/aggs.py | 4 ++++ tests/test_aggs.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/elasticsearch_dsl/aggs.py b/elasticsearch_dsl/aggs.py index d30716400..05e2db333 100644 --- a/elasticsearch_dsl/aggs.py +++ b/elasticsearch_dsl/aggs.py @@ -189,6 +189,10 @@ class Parent(Bucket): name = "parent" +class AdjacencyMatrix(Bucket): + name = "adjacency_matrix" + + class DateHistogram(Bucket): name = "date_histogram" diff --git a/tests/test_aggs.py b/tests/test_aggs.py index 6c39383a3..1919aee45 100644 --- a/tests/test_aggs.py +++ b/tests/test_aggs.py @@ -112,6 +112,25 @@ def test_A_fails_with_agg_and_params(): aggs.A(a, field="score") +def test_adjacency_matrix(): + filters = { + "grpA": {"terms": {"accounts": ["hillary", "sidney"]}}, + "grpB": {"terms": {"accounts": ["donald", "mitt"]}}, + "grpC": {"terms": {"accounts": ["vladimir", "nigel"]}}, + } + + a = aggs.AdjacencyMatrix(filters=filters) + assert { + "adjacency_matrix": { + "filters": { + "grpA": {"terms": {"accounts": ["hillary", "sidney"]}}, + "grpB": {"terms": {"accounts": ["donald", "mitt"]}}, + "grpC": {"terms": {"accounts": ["vladimir", "nigel"]}} + } + } + } == a.to_dict() + + def test_buckets_are_nestable(): a = aggs.Terms(field="tags") b = a.bucket("per_author", "terms", field="author.raw")