Skip to content

Commit

Permalink
[SearchSource] Deserialize query string options for serverside ES Query
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Feb 2, 2021
1 parent ad67ee5 commit a716765
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('Query decorator', () => {
expect(decoratedQuery).toEqual({ query_string: { query: '*', analyze_wildcard: true } });
});

test('should merge in serialized query string options', () => {
const queryStringOptions = '{ "analyze_wildcard": true }';
const decoratedQuery = decorateQuery({ query_string: { query: '*' } }, queryStringOptions);

expect(decoratedQuery).toEqual({ query_string: { query: '*', analyze_wildcard: true } });
});

test('should add a default of a time_zone parameter if one is provided', () => {
const decoratedQuery = decorateQuery(
{ query_string: { query: '*' } },
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/data/common/es_query/es_query/decorate_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ import { DslQuery, isEsQueryString } from './es_query_dsl';

export function decorateQuery(
query: DslQuery,
queryStringOptions: Record<string, any>,
queryStringOptions: Record<string, any> | string,
dateFormatTZ?: string
) {
if (isEsQueryString(query)) {
// NOTE queryStringOptions comes from UI Settings and, in server context, is a serialized string
// https://github.com/elastic/kibana/issues/89902
if (typeof queryStringOptions === 'string') {
queryStringOptions = JSON.parse(queryStringOptions);
}

extend(query.query_string, queryStringOptions);
if (dateFormatTZ) {
defaults(query.query_string, {
Expand Down

0 comments on commit a716765

Please sign in to comment.