Elasticsearch: Fix handling of inline scripts in different ES versions (#34070)

* Devenv: add block for es 5.0, provisioned datasource & dashboard

* Trasnsform script property based on running ES version

* Handle different scripts format in BE
This commit is contained in:
Giordano Ricci
2021-05-14 11:50:15 +01:00
committed by GitHub
parent ddb2fc1ae6
commit 8ec87250c1
11 changed files with 1339 additions and 334 deletions

View File

@@ -346,7 +346,8 @@ export class ElasticQueryBuilder {
Object.entries(metric.settings || {})
.filter(([_, v]) => v !== null)
.forEach(([k, v]) => {
metricAgg[k] = k === 'script' ? getScriptValue(metric as MetricAggregationWithInlineScript) : v;
metricAgg[k] =
k === 'script' ? this.buildScript(getScriptValue(metric as MetricAggregationWithInlineScript)) : v;
});
// Elasticsearch isn't generally too picky about the data types in the request body,
@@ -388,6 +389,16 @@ export class ElasticQueryBuilder {
return query;
}
private buildScript(script: string) {
if (gte(this.esVersion, '5.6.0')) {
return script;
}
return {
inline: script,
};
}
private toNumber(stringValue: unknown): unknown | number {
const parsedValue = parseFloat(`${stringValue}`);
if (isNaN(parsedValue)) {