Skip to content

Commit

Permalink
Added "adjacency_matrix" and "top_metrics" aggregations (#1788) (#1815)
Browse files Browse the repository at this point in the history
Fixes #1553
Fixes #1706

(cherry picked from commit ea0054f)

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
  • Loading branch information
github-actions[bot] and miguelgrinberg committed Apr 30, 2024
1 parent e1cfee3 commit c5df785
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions elasticsearch_dsl/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ class AutoDateHistogram(DateHistogram):
name = "auto_date_histogram"


class AdjacencyMatrix(Bucket):
name = "adjacency_matrix"


class DateRange(Bucket):
name = "date_range"

Expand Down Expand Up @@ -385,6 +389,10 @@ class Sum(Agg):
name = "sum"


class TopMetrics(Agg):
name = "top_metrics"


class TTest(Agg):
name = "t_test"

Expand Down
27 changes: 27 additions & 0 deletions tests/test_aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,30 @@ def test_random_sampler_aggregation():
},
},
} == a.to_dict()


def test_adjancecy_matrix_aggregation():
a = aggs.AdjacencyMatrix(
filters={
"grpA": {"terms": {"accounts": ["hillary", "sidney"]}},
"grpB": {"terms": {"accounts": ["donald", "mitt"]}},
"grpC": {"terms": {"accounts": ["vladimir", "nigel"]}},
}
)
assert {
"adjacency_matrix": {
"filters": {
"grpA": {"terms": {"accounts": ["hillary", "sidney"]}},
"grpB": {"terms": {"accounts": ["donald", "mitt"]}},
"grpC": {"terms": {"accounts": ["vladimir", "nigel"]}},
}
}
} == a.to_dict()


def test_top_metrics_aggregation():
a = aggs.TopMetrics(metrics={"field": "m"}, sort={"s": "desc"})

assert {
"top_metrics": {"metrics": {"field": "m"}, "sort": {"s": "desc"}}
} == a.to_dict()

0 comments on commit c5df785

Please sign in to comment.