Skip to content

Commit c5df785

Browse files
Added "adjacency_matrix" and "top_metrics" aggregations (#1788) (#1815)
Fixes #1553 Fixes #1706 (cherry picked from commit ea0054f) Co-authored-by: Miguel Grinberg <[email protected]>
1 parent e1cfee3 commit c5df785

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

elasticsearch_dsl/aggs.py

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class AutoDateHistogram(DateHistogram):
197197
name = "auto_date_histogram"
198198

199199

200+
class AdjacencyMatrix(Bucket):
201+
name = "adjacency_matrix"
202+
203+
200204
class DateRange(Bucket):
201205
name = "date_range"
202206

@@ -385,6 +389,10 @@ class Sum(Agg):
385389
name = "sum"
386390

387391

392+
class TopMetrics(Agg):
393+
name = "top_metrics"
394+
395+
388396
class TTest(Agg):
389397
name = "t_test"
390398

tests/test_aggs.py

+27
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,30 @@ def test_random_sampler_aggregation():
449449
},
450450
},
451451
} == a.to_dict()
452+
453+
454+
def test_adjancecy_matrix_aggregation():
455+
a = aggs.AdjacencyMatrix(
456+
filters={
457+
"grpA": {"terms": {"accounts": ["hillary", "sidney"]}},
458+
"grpB": {"terms": {"accounts": ["donald", "mitt"]}},
459+
"grpC": {"terms": {"accounts": ["vladimir", "nigel"]}},
460+
}
461+
)
462+
assert {
463+
"adjacency_matrix": {
464+
"filters": {
465+
"grpA": {"terms": {"accounts": ["hillary", "sidney"]}},
466+
"grpB": {"terms": {"accounts": ["donald", "mitt"]}},
467+
"grpC": {"terms": {"accounts": ["vladimir", "nigel"]}},
468+
}
469+
}
470+
} == a.to_dict()
471+
472+
473+
def test_top_metrics_aggregation():
474+
a = aggs.TopMetrics(metrics={"field": "m"}, sort={"s": "desc"})
475+
476+
assert {
477+
"top_metrics": {"metrics": {"field": "m"}, "sort": {"s": "desc"}}
478+
} == a.to_dict()

0 commit comments

Comments
 (0)