From be05f0b16cb018a1e0f15f51cfe749bbbcb6ddec Mon Sep 17 00:00:00 2001 From: friol Date: Sat, 24 Aug 2019 22:26:27 +0200 Subject: [PATCH] Possibility to filter when testing scripted fields --- .../components/scripting_help/test_script.js | 23 ++++++++++++++++++- .../field_editor/lib/validate_script.js | 6 ++++- 2 files changed, 27 insertions(+), 2 deletions(-) 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 04a457c118e55..9b20d93ed1908 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 @@ -29,12 +29,16 @@ import { EuiSpacer, EuiTitle, EuiCallOut, + EuiFieldText, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; + export class TestScript extends Component { state = { isLoading: false, additionalFields: [], + searchQuery: '', } componentDidMount() { @@ -65,6 +69,7 @@ export class TestScript extends Component { lang, script, indexPatternTitle: indexPattern.title, + additionalQuery: this.state.searchQuery, additionalFields: this.state.additionalFields.map(option => { return option.value; }) @@ -181,6 +186,22 @@ export class TestScript extends Component { /> + + + { + this.setState({ + searchQuery: e.target.value, + }); + }} + /> + + + 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. + additional 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 f8940447abc68..3f01d42e5f6af 100644 --- a/src/legacy/ui/public/field_editor/lib/validate_script.js +++ b/src/legacy/ui/public/field_editor/lib/validate_script.js @@ -19,7 +19,7 @@ import { kfetch } from 'ui/kfetch'; -export const executeScript = async ({ name, lang, script, indexPatternTitle, additionalFields = [] }) => { +export const executeScript = async ({ name, lang, script, indexPatternTitle, additionalQuery = '', additionalFields = [] }) => { // Using _msearch because _search with index name in path dorks everything up const header = { index: indexPatternTitle, @@ -46,6 +46,10 @@ export const executeScript = async ({ name, lang, script, indexPatternTitle, add search._source = additionalFields; } + if (additionalQuery !== '') { + search.query = { query_string: { query: additionalQuery } }; + } + const body = `${JSON.stringify(header)}\n${JSON.stringify(search)}\n`; const esResp = await kfetch({ method: 'POST', pathname: '/elasticsearch/_msearch', body }); // unwrap _msearch response