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
24 changes: 24 additions & 0 deletions pybana/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
}
}
},
"coreMigrationVersion": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"created_at": {
"type": "date"
},
"dashboard": {
"properties": {
"description": {
Expand Down Expand Up @@ -240,6 +252,9 @@
}
}
},
"managed": {
"type": "boolean"
},
"map": {
"properties": {
"bounds": {
Expand Down Expand Up @@ -456,6 +471,15 @@
"type": {
"type": "keyword"
},
"typeMigrationVersion": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"updated_at": {
"type": "date"
},
Expand Down
13 changes: 13 additions & 0 deletions pybana/translators/elastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@
from .filter import FilterTranslator
from .utils import SearchListProxy


__all__ = ("ElasticTranslator", "FilterTranslator")


class SignificantTerms(elasticsearch_dsl.query.Terms):
name = "significant_terms"


class TopMetrics(elasticsearch_dsl.aggs.TopHits):
name = "top_metrics"


elasticsearch_dsl.query.Query._classes[SignificantTerms.name] = SignificantTerms
elasticsearch_dsl.aggs.Agg._classes[TopMetrics.name] = TopMetrics


class ElasticTranslator:
def __init__(self, using):
self._using = using
Expand Down
19 changes: 16 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,20 @@ def translate(self, agg, state, context, field):
}


class TermsBucket(BaseBucket):
aggtype = "terms"


class SignificantTermsBucket(BaseBucket):
aggtype = "significant_terms"

def translate(self, agg, state, context, field):
ret = agg["params"]
if field and field.get("scripted"):
ret["valueType"] = field["type"]
return ret


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

Expand Down
25 changes: 24 additions & 1 deletion pybana/translators/elastic/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,35 @@ def translate(self, proxy, agg, state, field):
params = agg["params"]
proxy.metric(
agg["id"],
"top_hits",
self.aggtype,
sort={params["sortField"]: {"order": params["sortOrder"]}},
size=params["size"],
_source=agg["params"]["field"],
)


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

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

aggtype = "top_metrics"

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"],
metrics={"field": agg["params"]["field"]},
)


TRANSLATORS = {
translator.aggtype: translator
for translator in (
Expand All @@ -153,6 +175,7 @@ def translate(self, proxy, agg, state, field):
StdDevMetric,
SumMetric,
TopHitsMetric,
TopMetricsMetric,
)
}

Expand Down
18 changes: 18 additions & 0 deletions pybana/translators/vega/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ def flatten(value):
return ", ".join(map(str, values))


class TopMetricsMetric(BaseMetric):
"""
Metric for top_metrics.
"""

aggtype = "top_metrics"

def contribute(self, agg, bucket, response):
hit = bucket[agg["id"]]["top"][0]
value = (
hit["metrics"][agg["params"]["field"]]
if agg["params"]["field"] in hit["metrics"]
else None
)
return value


VEGA_METRICS = {
metric.aggtype: metric
for metric in [
Expand All @@ -122,5 +139,6 @@ def flatten(value):
StdDevMetric,
SumMetric,
TopHitsMetric,
TopMetricsMetric,
]
}