Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pybana/translators/elastic/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def translate(self, agg, state, context, field):
}


class TermsBucket(BaseBucket):
aggtype = "terms"

class BaseTermsBucket(BaseBucket):
def translate(self, agg, state, context, field):
orderby = agg["params"]["orderBy"]
aggs = {agg["id"]: agg for agg in state["aggs"]}
Expand All @@ -178,6 +176,14 @@ def translate(self, agg, state, context, field):
}


class TermsBucket(BaseBucket):
aggtype = "terms"


class SignificantTermsBucket(BaseBucket):
aggtype = "significant_terms"


TRANSLATORS = {
translator.aggtype: translator
for translator in (
Expand All @@ -187,6 +193,7 @@ def translate(self, agg, state, context, field):
HistogramBucket,
RangeBucket,
TermsBucket,
SignificantTermsBucket,
)
}

Expand Down
35 changes: 25 additions & 10 deletions pybana/translators/elastic/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@ def translate(self, proxy, agg, state, field):
pass


class TopHitsMetric(BaseMetric):
class BaseTopMetric(BaseMetric):
def translate(self, proxy, agg, state, field):
params = agg["params"]
proxy.metric(
agg["id"],
self.aggtype,
sort={params["sortField"]: {"order": params["sortOrder"]}},
size=params["size"],
_source=agg["params"]["field"],
)


class TopHitsMetric(BaseTopMetric):
"""
Translator for top_hits metric.

Expand All @@ -127,15 +139,17 @@ class TopHitsMetric(BaseMetric):

aggtype = "top_hits"

def translate(self, proxy, agg, state, field):
params = agg["params"]
proxy.metric(
agg["id"],
"top_hits",
sort={params["sortField"]: {"order": params["sortOrder"]}},
size=params["size"],
_source=agg["params"]["field"],
)

class TopMetricsMetric(BaseTopMetric):
"""
Translator for top_metrics metric.

Careful, this metric is partially supported:
- date fields are not handled.
- scripted fields are not handled.
"""

aggtype = "top_metrics"


TRANSLATORS = {
Expand All @@ -153,6 +167,7 @@ def translate(self, proxy, agg, state, field):
StdDevMetric,
SumMetric,
TopHitsMetric,
TopMetricsMetric,
)
}

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
elasticsearch==6.4.0
elasticsearch-dsl==6.4.0
elasticsearch==8.17.1
elasticsearch-dsl==8.17.1
hjson==3.0.1
pendulum==2.1.2
pytz>=2019.1
Expand Down