Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to filter when testing scripted fields (#35379) #44220

Merged
merged 16 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/legacy/ui/public/field_editor/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import './components/field_format_editor/samples/index';
@import './components/scripting_help/test_script';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.testScript__searchBar {
.globalQueryBar {
padding: $euiSize 0 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jest.mock('ui/documentation_links', () => ({
getDocLink: doc => `(docLink for ${doc})`,
}));

jest.mock('./test_script', () => ({
TestScript: () => {
return `<div>mockTestScript</div>`;
},
}));

const indexPatternMock = {};

describe('ScriptingHelpFlyout', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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;
}),
Expand Down Expand Up @@ -161,24 +180,36 @@ export class TestScript extends Component {

return (
<Fragment>
<EuiFormRow label="Additional fields">
<EuiFormRow label="Additional fields" fullWidth>
<EuiComboBox
placeholder="Select..."
options={fields}
selectedOptions={this.state.additionalFields}
onChange={this.onAdditionalFieldsChange}
data-test-subj="additionalFieldsSelect"
fullWidth
/>
</EuiFormRow>

<EuiButton
onClick={this.previewScript}
disabled={this.props.script ? false : true}
isLoading={this.state.isLoading}
data-test-subj="runScriptButton"
>
Run script
</EuiButton>
<div className="testScript__searchBar">
<SearchBar
showFilterBar={false}
showDatePicker={false}
showQueryInput={true}
query={{ language: uiSettings.get('search:queryLanguage'), query: '' }}
onQuerySubmit={this.previewScript}
indexPatterns={[this.props.indexPattern]}
customSubmitButton={
<EuiButton
disabled={this.props.script ? false : true}
isLoading={this.state.isLoading}
data-test-subj="runScriptButton"
>
Run script
</EuiButton>
}
/>
</div>
</Fragment>
);
}
Expand All @@ -191,7 +222,8 @@ export class TestScript extends Component {
<h3>Preview results</h3>
<p>
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.
</p>
</EuiText>
<EuiSpacer />
Expand Down
5 changes: 5 additions & 0 deletions src/legacy/ui/public/field_editor/lib/validate_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand 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
Expand Down