diff --git a/src/ui/public/agg_types/agg_params.js b/src/ui/public/agg_types/agg_params.js
index 22e85cf12a73a..9d49251b8fa90 100644
--- a/src/ui/public/agg_types/agg_params.js
+++ b/src/ui/public/agg_types/agg_params.js
@@ -7,6 +7,7 @@ import AggTypesParamTypesRegexProvider from 'ui/agg_types/param_types/regex';
import AggTypesParamTypesStringProvider from 'ui/agg_types/param_types/string';
import AggTypesParamTypesRawJsonProvider from 'ui/agg_types/param_types/raw_json';
import AggTypesParamTypesBaseProvider from 'ui/agg_types/param_types/base';
+import AggTypesParamTypesScriptingLangProvider from 'ui/agg_types/param_types/script_lang';
export default function AggParamsFactory(Private) {
@@ -16,6 +17,7 @@ export default function AggParamsFactory(Private) {
regex: Private(AggTypesParamTypesRegexProvider),
string: Private(AggTypesParamTypesStringProvider),
json: Private(AggTypesParamTypesRawJsonProvider),
+ script_lang: Private(AggTypesParamTypesScriptingLangProvider),
_default: Private(AggTypesParamTypesBaseProvider)
};
diff --git a/src/ui/public/agg_types/controls/script_lang.html b/src/ui/public/agg_types/controls/script_lang.html
new file mode 100644
index 0000000000000..2c170e0e02e55
--- /dev/null
+++ b/src/ui/public/agg_types/controls/script_lang.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/ui/public/agg_types/controls/text.html b/src/ui/public/agg_types/controls/text.html
new file mode 100644
index 0000000000000..d10fcf6b0de2a
--- /dev/null
+++ b/src/ui/public/agg_types/controls/text.html
@@ -0,0 +1,6 @@
+
diff --git a/src/ui/public/agg_types/index.js b/src/ui/public/agg_types/index.js
index ad7af3709460e..23a05e9d447a0 100644
--- a/src/ui/public/agg_types/index.js
+++ b/src/ui/public/agg_types/index.js
@@ -10,6 +10,7 @@ import AggTypesMetricsStdDeviationProvider from 'ui/agg_types/metrics/std_deviat
import AggTypesMetricsCardinalityProvider from 'ui/agg_types/metrics/cardinality';
import AggTypesMetricsPercentilesProvider from 'ui/agg_types/metrics/percentiles';
import AggTypesMetricsPercentileRanksProvider from 'ui/agg_types/metrics/percentile_ranks';
+import AggTypesMetricsScriptedMetricProvider from 'ui/agg_types/metrics/scripted_metric';
import AggTypesBucketsDateHistogramProvider from 'ui/agg_types/buckets/date_histogram';
import AggTypesBucketsHistogramProvider from 'ui/agg_types/buckets/histogram';
import AggTypesBucketsRangeProvider from 'ui/agg_types/buckets/range';
@@ -32,7 +33,8 @@ export default function AggTypeService(Private) {
Private(AggTypesMetricsStdDeviationProvider),
Private(AggTypesMetricsCardinalityProvider),
Private(AggTypesMetricsPercentilesProvider),
- Private(AggTypesMetricsPercentileRanksProvider)
+ Private(AggTypesMetricsPercentileRanksProvider),
+ Private(AggTypesMetricsScriptedMetricProvider)
],
buckets: [
Private(AggTypesBucketsDateHistogramProvider),
diff --git a/src/ui/public/agg_types/metrics/scripted_metric.js b/src/ui/public/agg_types/metrics/scripted_metric.js
new file mode 100644
index 0000000000000..5809ea19230e5
--- /dev/null
+++ b/src/ui/public/agg_types/metrics/scripted_metric.js
@@ -0,0 +1,49 @@
+import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/metric_agg_type';
+import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
+import textHtml from 'ui/agg_types/controls/text.html';
+
+export default function AggTypesMetricsScriptedMetricProvider(Private) {
+ let MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
+ let fieldFormats = Private(RegistryFieldFormatsProvider);
+
+ const buildScriptParam = function (scriptName) {
+ return {
+ name: scriptName,
+ type: 'string',
+ editor: textHtml,
+ write:function (aggConfig, output) {
+ const inlineScript = aggConfig.params[scriptName];
+ if (!inlineScript) {
+ return;
+ }
+
+ output.params[scriptName] = {
+ lang: aggConfig.params.lang,
+ inline: inlineScript
+ };
+ }
+ };
+ };
+
+ return new MetricAggType({
+ name: 'scripted_metric',
+ title: 'Scripted Metric',
+ makeLabel: function () {
+ return 'Scripted Metric';
+ },
+ getFormat: function () {
+ return fieldFormats.getDefaultInstance('number');
+ },
+ params: [
+ {
+ name: 'lang',
+ type: 'script_lang',
+ write: function () {}
+ },
+ buildScriptParam('init_script'),
+ buildScriptParam('map_script'),
+ buildScriptParam('combine_script'),
+ buildScriptParam('reduce_script')
+ ]
+ });
+};
diff --git a/src/ui/public/agg_types/param_types/script_lang.js b/src/ui/public/agg_types/param_types/script_lang.js
new file mode 100644
index 0000000000000..2229ddfa6c74f
--- /dev/null
+++ b/src/ui/public/agg_types/param_types/script_lang.js
@@ -0,0 +1,31 @@
+import _ from 'lodash';
+import editorHtml from 'ui/agg_types/controls/script_lang.html';
+import StringParamTypesBaseProvider from 'ui/agg_types/param_types/string';
+import { GetScriptingLangsProvider } from 'ui/scripting_langs';
+
+export default function ScriptingLangAggParamFactory(Private) {
+ const StringAggParam = Private(StringParamTypesBaseProvider);
+ const getScriptingLangs = Private(GetScriptingLangsProvider);
+
+ class ScriptingLangAggParam extends StringAggParam {
+ constructor(config) {
+ super(config);
+
+ this.default = 'painless';
+ this.editor = editorHtml;
+ this.controller = class ScriptingLangParamController {
+ constructor($scope) {
+ this.loading = true;
+
+ getScriptingLangs()
+ .then(scriptingLangs => {
+ this.loading = false;
+ this.scriptingLangs = scriptingLangs;
+ });
+ };
+ };
+ }
+ }
+
+ return ScriptingLangAggParam;
+};
diff --git a/src/ui/public/field_editor/field_editor.js b/src/ui/public/field_editor/field_editor.js
index 71a81d1226903..16c07a3d84684 100644
--- a/src/ui/public/field_editor/field_editor.js
+++ b/src/ui/public/field_editor/field_editor.js
@@ -6,18 +6,17 @@ import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
import IndexPatternsFieldProvider from 'ui/index_patterns/_field';
import uiModules from 'ui/modules';
import fieldEditorTemplate from 'ui/field_editor/field_editor.html';
-import chrome from 'ui/chrome';
import IndexPatternsCastMappingTypeProvider from 'ui/index_patterns/_cast_mapping_type';
import { scriptedFields as docLinks } from '../documentation_links/documentation_links';
import './field_editor.less';
-import { GetEnabledScriptingLanguagesProvider, getSupportedScriptingLanguages } from '../scripting_languages';
+import { GetScriptingLangsProvider } from 'ui/scripting_langs';
uiModules
.get('kibana', ['colorpicker.module'])
.directive('fieldEditor', function (Private, $sce) {
const fieldFormats = Private(RegistryFieldFormatsProvider);
const Field = Private(IndexPatternsFieldProvider);
- const getEnabledScriptingLanguages = Private(GetEnabledScriptingLanguagesProvider);
+ const getScriptingLangs = Private(GetScriptingLangsProvider);
const fieldTypesByLang = {
painless: ['number', 'string', 'date', 'boolean'],
@@ -33,7 +32,7 @@ uiModules
getField: '&field'
},
controllerAs: 'editor',
- controller: function ($scope, Notifier, kbnUrl, $http, $q) {
+ controller: function ($scope, Notifier, kbnUrl, $http) {
const self = this;
const notify = new Notifier({ location: 'Field Editor' });
@@ -160,13 +159,6 @@ uiModules
else return fieldFormats.getDefaultType(self.field.type);
}
- function getScriptingLangs() {
- return getEnabledScriptingLanguages()
- .then((enabledLanguages) => {
- return _.intersection(enabledLanguages, getSupportedScriptingLanguages());
- });
- }
-
function initDefaultFormat() {
const def = Object.create(fieldFormats.getDefaultType(self.field.type));
diff --git a/src/ui/public/scripting_langs/scripting_langs.js b/src/ui/public/scripting_langs/scripting_langs.js
new file mode 100644
index 0000000000000..64a81484d092c
--- /dev/null
+++ b/src/ui/public/scripting_langs/scripting_langs.js
@@ -0,0 +1,16 @@
+import uiModules from 'ui/modules';
+import chrome from 'ui/chrome';
+import Notifier from 'ui/notify/notifier';
+
+const notify = new Notifier({ location: 'Scripting Lang Service' });
+
+export function GetScriptingLangsProvider($http) {
+ return () => {
+ return $http.get(chrome.addBasePath('/api/kibana/scripts/languages'))
+ .then((res) => res.data)
+ .catch(() => {
+ notify.error('Error getting available scripting languages from Elasticsearch');
+ return [];
+ });
+ };
+}