From b3a569dbfb97b91f2b7eab4c93b06ea0625aa386 Mon Sep 17 00:00:00 2001 From: Jared Carey Date: Sun, 20 Aug 2017 14:39:50 -0600 Subject: [PATCH 1/4] highlighting for scripted metric agg scripts Adding detection for [scripted metric aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-metrics-scripted-metric-aggregation.html) ```json POST ledger/_search?size=0 { "query" : { "match_all" : {} }, "aggs": { "profit": { "scripted_metric": { "init_script" : "params._agg.transactions = []", "map_script" : "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)", "combine_script" : "double profit = 0; for (t in params._agg.transactions) { profit += t } return profit", "reduce_script" : "double profit = 0; for (a in params._aggs) { profit += a } return profit" } } } } ``` --- .../public/src/sense_editor/mode/x_json_highlight_rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js index 4b1d0e3d1c06a..2a402f5fa21a6 100644 --- a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js @@ -7,7 +7,7 @@ var jsonRules = function (root) { rules[root] = [ { token: ["variable", "whitespace", "ace.punctuation.colon", "whitespace", "punctuation.start_triple_quote"], - regex: '("script"|"inline")(\\s*?)(:)(\\s*?)(""")', + regex: '("script"|"inline"|"init_script"|"map_script"|"combine_script"|"reduce_script")(\\s*?)(:)(\\s*?)(""")', next: "script-start", merge: false, push: true From 2f6435d04e4d86dad88d321af690e8e650265dd4 Mon Sep 17 00:00:00 2001 From: Jared Carey Date: Tue, 22 Aug 2017 12:27:25 -0600 Subject: [PATCH 2/4] Update x_json_highlight_rules.js --- .../public/src/sense_editor/mode/x_json_highlight_rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js index 2a402f5fa21a6..58af6ce01c0af 100644 --- a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js @@ -7,7 +7,7 @@ var jsonRules = function (root) { rules[root] = [ { token: ["variable", "whitespace", "ace.punctuation.colon", "whitespace", "punctuation.start_triple_quote"], - regex: '("script"|"inline"|"init_script"|"map_script"|"combine_script"|"reduce_script")(\\s*?)(:)(\\s*?)(""")', + regex: '("([^"]*_)?script"|"inline")(\\s*?)(:)(\\s*?)(""")', next: "script-start", merge: false, push: true From b60390c241ecd8f3cc5c0ac137aa817b3068ef0c Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 4 Dec 2017 09:54:18 -0600 Subject: [PATCH 3/4] [console] Remove capture group from *_script check --- .../public/src/sense_editor/mode/x_json_highlight_rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js index 58af6ce01c0af..47945827f8128 100644 --- a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js @@ -7,7 +7,7 @@ var jsonRules = function (root) { rules[root] = [ { token: ["variable", "whitespace", "ace.punctuation.colon", "whitespace", "punctuation.start_triple_quote"], - regex: '("([^"]*_)?script"|"inline")(\\s*?)(:)(\\s*?)(""")', + regex: '("(?:[^"]*_)?script"|"inline")(\\s*?)(:)(\\s*?)(""")', next: "script-start", merge: false, push: true From 9e2d5aee2a91a5e7232784ede051ad6984338aa8 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Fri, 2 Feb 2018 09:56:15 -0600 Subject: [PATCH 4/4] allow source --- .../public/src/sense_editor/mode/x_json_highlight_rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js index 47945827f8128..bddca4f688784 100644 --- a/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/core_plugins/console/public/src/sense_editor/mode/x_json_highlight_rules.js @@ -7,7 +7,7 @@ var jsonRules = function (root) { rules[root] = [ { token: ["variable", "whitespace", "ace.punctuation.colon", "whitespace", "punctuation.start_triple_quote"], - regex: '("(?:[^"]*_)?script"|"inline")(\\s*?)(:)(\\s*?)(""")', + regex: '("(?:[^"]*_)?script"|"inline"|"source")(\\s*?)(:)(\\s*?)(""")', next: "script-start", merge: false, push: true