diff --git a/src/legacy/ui/public/field_editor/_index.scss b/src/legacy/ui/public/field_editor/_index.scss
index 9c94861eb74aa..39f69c013d428 100644
--- a/src/legacy/ui/public/field_editor/_index.scss
+++ b/src/legacy/ui/public/field_editor/_index.scss
@@ -1 +1,2 @@
@import './components/field_format_editor/samples/index';
+@import './components/scripting_help/test_script';
diff --git a/src/legacy/ui/public/field_editor/components/scripting_help/__snapshots__/help_flyout.test.js.snap b/src/legacy/ui/public/field_editor/components/scripting_help/__snapshots__/help_flyout.test.js.snap
index b2ee13e865a9a..ca252b6d0147b 100644
--- a/src/legacy/ui/public/field_editor/components/scripting_help/__snapshots__/help_flyout.test.js.snap
+++ b/src/legacy/ui/public/field_editor/components/scripting_help/__snapshots__/help_flyout.test.js.snap
@@ -34,7 +34,6 @@ exports[`ScriptingHelpFlyout should render normally 1`] = `
executeScript={[Function]}
indexPattern={Object {}}
lang="painless"
- name="myScriptedField"
/>,
"data-test-subj": "testTab",
"id": "test",
diff --git a/src/legacy/ui/public/field_editor/components/scripting_help/_test_script.scss b/src/legacy/ui/public/field_editor/components/scripting_help/_test_script.scss
new file mode 100644
index 0000000000000..34e8a60d07074
--- /dev/null
+++ b/src/legacy/ui/public/field_editor/components/scripting_help/_test_script.scss
@@ -0,0 +1,5 @@
+.testScript__searchBar {
+ .globalQueryBar {
+ padding: $euiSize 0 0;
+ }
+}
diff --git a/src/legacy/ui/public/field_editor/components/scripting_help/help_flyout.test.js b/src/legacy/ui/public/field_editor/components/scripting_help/help_flyout.test.js
index 69e6f9430b4e1..2fac8c7641ddb 100644
--- a/src/legacy/ui/public/field_editor/components/scripting_help/help_flyout.test.js
+++ b/src/legacy/ui/public/field_editor/components/scripting_help/help_flyout.test.js
@@ -26,6 +26,12 @@ jest.mock('ui/documentation_links', () => ({
getDocLink: doc => `(docLink for ${doc})`,
}));
+jest.mock('./test_script', () => ({
+ TestScript: () => {
+ return `
mockTestScript
`;
+ },
+}));
+
const indexPatternMock = {};
describe('ScriptingHelpFlyout', () => {
diff --git a/src/legacy/ui/public/field_editor/components/scripting_help/test_script.js b/src/legacy/ui/public/field_editor/components/scripting_help/test_script.js
index 08d22af66e451..942f39fc98dec 100644
--- a/src/legacy/ui/public/field_editor/components/scripting_help/test_script.js
+++ b/src/legacy/ui/public/field_editor/components/scripting_help/test_script.js
@@ -31,6 +31,13 @@ import {
EuiCallOut,
} from '@elastic/eui';
+import { npStart } from 'ui/new_platform';
+const { SearchBar } = npStart.plugins.data.ui;
+
+const { uiSettings } = npStart.core;
+
+import { esQuery } from '../../../../../../plugins/data/public';
+
export class TestScript extends Component {
state = {
isLoading: false,
@@ -43,7 +50,7 @@ export class TestScript extends Component {
}
}
- previewScript = async () => {
+ previewScript = async searchContext => {
const { indexPattern, lang, name, script, executeScript } = this.props;
if (!script || script.length === 0) {
@@ -54,11 +61,23 @@ export class TestScript extends Component {
isLoading: true,
});
+ let query;
+ if (searchContext) {
+ const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);
+ query = esQuery.buildEsQuery(
+ this.props.indexPattern,
+ searchContext.query,
+ null,
+ esQueryConfigs
+ );
+ }
+
const scriptResponse = await executeScript({
name,
lang,
script,
indexPatternTitle: indexPattern.title,
+ query,
additionalFields: this.state.additionalFields.map(option => {
return option.value;
}),
@@ -161,24 +180,36 @@ export class TestScript extends Component {
return (
-
+
-
- Run script
-
+
+
+ Run script
+
+ }
+ />
+
);
}
@@ -191,7 +222,8 @@ export class TestScript extends Component {
Preview results
Run your script to preview the first 10 results. You can also select some additional
- fields to include in your results to gain more context.
+ fields to include in your results to gain more context or add a query to filter on
+ specific documents.
diff --git a/src/legacy/ui/public/field_editor/lib/validate_script.js b/src/legacy/ui/public/field_editor/lib/validate_script.js
index ee51fe8858bc0..47e2091565c30 100644
--- a/src/legacy/ui/public/field_editor/lib/validate_script.js
+++ b/src/legacy/ui/public/field_editor/lib/validate_script.js
@@ -24,6 +24,7 @@ export const executeScript = async ({
lang,
script,
indexPatternTitle,
+ query,
additionalFields = [],
}) => {
// Using _msearch because _search with index name in path dorks everything up
@@ -52,6 +53,10 @@ export const executeScript = async ({
search._source = additionalFields;
}
+ if (query) {
+ search.query = query;
+ }
+
const body = `${JSON.stringify(header)}\n${JSON.stringify(search)}\n`;
const esResp = await kfetch({ method: 'POST', pathname: '/elasticsearch/_msearch', body });
// unwrap _msearch response