Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
21ce7ac
Move the add dataview action above the dataview selection panel
stratoula Jun 15, 2022
3364e53
Implements a new selectable on the dataview picker for the text based…
stratoula Jun 15, 2022
f6afba5
Implementation of the transition modal when on SQL mode and select a …
stratoula Jun 15, 2022
ad59ff0
Fix es lint
stratoula Jun 15, 2022
a7343e8
Change switch modal button modal icon
stratoula Jun 15, 2022
b5f6e43
Lazy load components
stratoula Jun 15, 2022
6464166
Small changes on the styling of the switch without saving button
stratoula Jun 16, 2022
c376456
Initialization of mocaco editor
stratoula Jun 17, 2022
abff0aa
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 17, 2022
84007c4
Change to the type
stratoula Jun 17, 2022
6a4f5ed
Fixes types checks
stratoula Jun 20, 2022
e3c437d
New submit button for query mode
stratoula Jun 20, 2022
edc5277
Implememtation of the expanded mode of the editor
stratoula Jun 20, 2022
dbe7d58
Implement documentation
stratoula Jun 21, 2022
6fc8e6f
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 21, 2022
69fed5f
Implementation of the oneliner mode with ellipsis
stratoula Jun 22, 2022
1d94bda
Some fixes on the resizer
stratoula Jun 22, 2022
8ae2f42
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 23, 2022
c6091d9
Implementation of the errors layout, WIP
stratoula Jun 23, 2022
9bea48b
Fetch SQL data in Discover
stratoula Jun 24, 2022
cbbd129
Fix expression test
stratoula Jun 24, 2022
617bf18
Fix editor zIndex
stratoula Jun 24, 2022
fa0295e
Fix types error
stratoula Jun 24, 2022
fb45949
Fix type check in Discover
stratoula Jun 24, 2022
d1ef05d
Fix more types
stratoula Jun 24, 2022
160eb05
some CI fixes
stratoula Jun 24, 2022
9018351
Fixes
stratoula Jun 24, 2022
49b115e
Merge with feature branch and reslove conflicts
stratoula Jun 27, 2022
8661b3e
Cleanup after merge
stratoula Jun 27, 2022
10f7040
Remove from state
stratoula Jun 27, 2022
29c9baa
Connect search errors with the unified search editor
stratoula Jun 27, 2022
6be485c
Add error mrkers in unified search editor
stratoula Jun 27, 2022
5f0d0ed
Save and open saved searches
stratoula Jun 27, 2022
e3ad0b3
Filter out saved searches from text based languages
stratoula Jun 27, 2022
22119af
Some fixes
stratoula Jun 27, 2022
d538306
Fix unit tests
stratoula Jun 28, 2022
e7d19e5
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 28, 2022
c920a64
Fix checks
stratoula Jun 28, 2022
9cff6ef
On save and exit modal implementation
stratoula Jun 28, 2022
7bc9c2b
Add shortcut on the editor for submit query
stratoula Jun 28, 2022
87297c0
Fix wrong condition
stratoula Jun 28, 2022
58412fb
Initial types change
stratoula Jun 28, 2022
75efd80
Use regex to find the index pattern string
stratoula Jun 28, 2022
2c0730e
Fix some types and cleanup
stratoula Jun 28, 2022
39dede2
Fix types
stratoula Jun 28, 2022
2b12065
Fix some types
stratoula Jun 28, 2022
41c9097
Further fixes
stratoula Jun 28, 2022
cda9fce
More fixes
stratoula Jun 28, 2022
149e1e3
More fixes
stratoula Jun 28, 2022
a0a091b
Fix visualize types
stratoula Jun 28, 2022
b4f71cd
more
stratoula Jun 28, 2022
8b18e81
More fixes
stratoula Jun 28, 2022
933a3c1
Fixes more types
stratoula Jun 28, 2022
56b6890
Fix dashboard types
stratoula Jun 28, 2022
5791772
Fix dashboard types
stratoula Jun 28, 2022
cd96911
Controls plugin types
stratoula Jun 28, 2022
a15d6df
Fix Lens types
stratoula Jun 28, 2022
41b1d98
Fix data plugin types
stratoula Jun 28, 2022
1ec54d4
Fix types in Lens 2
stratoula Jun 28, 2022
0755330
buildEsConfig type fixes
stratoula Jun 28, 2022
9c17d3a
Fix observability types
stratoula Jun 28, 2022
47aa9b0
Fix maps types
stratoula Jun 28, 2022
a79a075
data visualizer types
stratoula Jun 28, 2022
141682c
Fix ml types
stratoula Jun 28, 2022
f75b525
xpack rest types
stratoula Jun 28, 2022
20246b1
Fix jest test
stratoula Jun 28, 2022
8e3f67c
Merge pull request #20 from stratoula/text-based-language-types
stratoula Jun 29, 2022
a504472
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 29, 2022
40b63ba
Fix
stratoula Jun 29, 2022
07e7079
Move helper functions to es config
stratoula Jun 29, 2022
84c5128
fix bug on breadcrumb click
stratoula Jun 29, 2022
d32ff4f
Fix time field bug
stratoula Jun 29, 2022
5994fa5
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 30, 2022
3b88870
Add enableSql advanced setting to discover for enabling the sql mode
stratoula Jun 30, 2022
9ac6c27
Make the documentation component more dynamic
stratoula Jun 30, 2022
07a3cf5
Add some comments, improvements
stratoula Jun 30, 2022
caee80d
Enhance storybook with the textbased languages
stratoula Jun 30, 2022
606b6d7
Update storybook with the error state of the editor
stratoula Jun 30, 2022
654b4a6
Adds a readme for the editor and fixes the modal mobile version
stratoula Jun 30, 2022
e64e358
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jun 30, 2022
6ea3d2a
[Discover] improve test and storybook for new data type
dimaanj Jul 2, 2022
ad712de
[Discover] add functional tests
dimaanj Jul 3, 2022
97ced81
Add aggregate functions to the documentation
stratoula Jul 4, 2022
8456015
[Discover] fix tests
dimaanj Jul 4, 2022
4a64882
Add some unit tests
stratoula Jul 4, 2022
2f7a36a
[Discover] fix linting
dimaanj Jul 4, 2022
90e3140
[Discover] update linting
dimaanj Jul 4, 2022
c4ac2d0
More unti tests
stratoula Jul 4, 2022
0b99300
Dataview picker unit tests
stratoula Jul 4, 2022
318bc92
Fix a bug on the dataview picker
stratoula Jul 5, 2022
9e697f7
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jul 5, 2022
aad76c3
Add unit tests for the editor
stratoula Jul 5, 2022
1a6ec3c
Fix jest test
stratoula Jul 5, 2022
5fd04b2
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
kibanamachine Jul 5, 2022
331f92a
[Discover] apply suggestions
dimaanj Jul 5, 2022
613d825
[Discover] adjust styles
dimaanj Jul 5, 2022
9335e2a
Fix some bugs and select columns in the sql mode
stratoula Jul 6, 2022
3703ad5
Merge branch 'text-based-lang-phase-1' of https://github.com/stratoul…
stratoula Jul 6, 2022
46476c5
[Discover] fix eslint and tests
dimaanj Jul 6, 2022
0556ba6
Merge remote-tracking branch 'stratoula-remote/text-based-lang-phase-…
dimaanj Jul 6, 2022
61634d5
Merge remote-tracking branch 'stratoula-remote/text-based-lang-phase-…
dimaanj Jul 6, 2022
06e1df4
[Discover] update unit tests
dimaanj Jul 6, 2022
ba9fd7a
Fix bug on transitioning from sql mode to dataview mode
stratoula Jul 6, 2022
9a20de2
[Discover] fix tests
dimaanj Jul 6, 2022
8e64c65
Design fixes on the errors messages
stratoula Jul 7, 2022
192d4c3
[Discover] fix ci
dimaanj Jul 7, 2022
b05026a
Merge remote-tracking branch 'stratoula-remote/text-based-lang-phase-…
dimaanj Jul 7, 2022
d6cbba7
Update the columns only if the query changes
stratoula Jul 7, 2022
367a3c6
Fix conflicts
stratoula Jul 7, 2022
be61199
[Discover] change isPlainRecord retrieval method
dimaanj Jul 7, 2022
cb6e586
Fix bug on cleanup
stratoula Jul 7, 2022
5dc1c05
Fix bug on opening a saved search
stratoula Jul 7, 2022
36ef700
Merge remote-tracking branch 'stratoula-remote/text-based-lang-phase-…
dimaanj Jul 8, 2022
95691c3
Merge with feature branch and resolve conflicts
stratoula Jul 8, 2022
b24d719
Merge remote-tracking branch 'stratoula-remote/text-based-lang-phase-…
dimaanj Jul 8, 2022
09946a0
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
kibanamachine Jul 8, 2022
1cb55f1
Merge with feature branch and resolve conflicts
stratoula Jul 11, 2022
60c9ef9
[Discover] fix comments
dimaanj Jul 11, 2022
1239229
[Discover] fix bug with browser refresh
dimaanj Jul 11, 2022
680d96f
[Discover] fix functional
dimaanj Jul 11, 2022
b89fd23
Merge branch 'text-based-lang-phase-1' into improve-tests-and-storybo…
dimaanj Jul 12, 2022
2482c9e
[Discover] fix another functional
dimaanj Jul 12, 2022
1d40c5d
Fix ordering lost when the user refreshes the browser
stratoula Jul 13, 2022
141c8d6
[Discover] revert use_discover_state
dimaanj Jul 13, 2022
0b8c118
[Discover] revert functional impl
dimaanj Jul 13, 2022
7ee3875
Merge pull request #21 from dimaanj/improve-tests-and-storybook-for-n…
stratoula Jul 14, 2022
01e98aa
Merge with feature branch and resolve conflicts
stratoula Jul 14, 2022
53de946
Fix security solution types
stratoula Jul 14, 2022
7702a42
Merge branch 'unified-search-text-based-lang' into text-based-lang-ph…
stratoula Jul 18, 2022
6e010ca
Casting dashboard plugin
stratoula Jul 19, 2022
9893b54
Revert change
stratoula Jul 19, 2022
1fdbde6
type param
flash1293 Jul 19, 2022
0558e23
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jul 19, 2022
0dbdcd5
Revert types changes
stratoula Jul 19, 2022
39b27ed
More reverts
stratoula Jul 19, 2022
f6da616
Types fixes
stratoula Jul 19, 2022
602f4d2
Fix Discover jest test
stratoula Jul 19, 2022
eecfe9f
Fix context app jest test
stratoula Jul 19, 2022
95da2b3
Final types changes
stratoula Jul 19, 2022
0d205c6
Fixes unit test
stratoula Jul 19, 2022
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
3 changes: 3 additions & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ The default sort direction for time-based data views.
[[doctable-hidetimecolumn]]`doc_table:hideTimeColumn`::
Hides the "Time" column in *Discover* and in all saved searches on dashboards.

[[discover:enableSql]]`discover:enableSql`::
When enabled, allows SQL queries for search.

[[doctable-highlight]]`doc_table:highlight`::
Highlights results in *Discover* and saved searches on dashboards. Highlighting
slows requests when working on big documents.
Expand Down
8 changes: 5 additions & 3 deletions packages/kbn-es-query/src/es_query/build_es_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { SerializableRecord } from '@kbn/utility-types';
import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
import { Filter, Query } from '../filters';
import { Filter, Query, AggregateQuery } from '../filters';
import { isOfQueryType } from './es_query_sql';
import { BoolQuery, DataViewBase } from './types';
import type { KueryQueryOptions } from '../kuery';
import type { EsQueryFiltersConfig } from './from_filters';
Expand Down Expand Up @@ -44,7 +45,7 @@ function removeMatchAll<T>(filters: T[]) {
*/
export function buildEsQuery(
indexPattern: DataViewBase | undefined,
queries: Query | Query[],
queries: Query | AggregateQuery | Array<Query | AggregateQuery>,
filters: Filter | Filter[],
config: EsQueryConfig = {
allowLeadingWildcards: false,
Expand All @@ -55,7 +56,8 @@ export function buildEsQuery(
queries = Array.isArray(queries) ? queries : [queries];
filters = Array.isArray(filters) ? filters : [filters];

const validQueries = queries.filter((query) => has(query, 'query'));
const isOfQueryTypeQueries = queries.filter(isOfQueryType);
const validQueries = isOfQueryTypeQueries.filter((query) => has(query, 'query'));
const queriesByLanguage = groupBy(validQueries, 'language');
const kueryQuery = buildQueryFromKuery(
indexPattern,
Expand Down
79 changes: 79 additions & 0 deletions packages/kbn-es-query/src/es_query/es_query_sql.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import {
isOfQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
} from './es_query_sql';

describe('sql query helpers', () => {
describe('isOfQueryType', () => {
it('should return true for a Query type query', () => {
const flag = isOfQueryType({ query: 'foo', language: 'test' });
expect(flag).toBe(true);
});

it('should return false for an Aggregate type query', () => {
const flag = isOfQueryType({ sql: 'SELECT * FROM foo' });
expect(flag).toBe(false);
});
});

describe('isOfAggregateQueryType', () => {
it('should return false for a Query type query', () => {
const flag = isOfAggregateQueryType({ query: 'foo', language: 'test' });
expect(flag).toBe(false);
});

it('should return true for an Aggregate type query', () => {
const flag = isOfAggregateQueryType({ sql: 'SELECT * FROM foo' });
expect(flag).toBe(true);
});
});

describe('getAggregateQueryMode', () => {
it('should return sql for an SQL AggregateQuery type', () => {
const mode = getAggregateQueryMode({ sql: 'SELECT * FROM foo' });
expect(mode).toBe('sql');
});

it('should return esql for an ESQL AggregateQuery type', () => {
const mode = getAggregateQueryMode({ esql: 'foo | where field > 100' });
expect(mode).toBe('esql');
});
});

describe('getIndexPatternFromSQLQuery', () => {
it('should return the index pattern string from sql queries', () => {
const idxPattern1 = getIndexPatternFromSQLQuery('SELECT * FROM foo');
expect(idxPattern1).toBe('foo');

const idxPattern2 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "foo"');
expect(idxPattern2).toBe('foo');

const idxPattern3 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "the_index_pattern"');
expect(idxPattern3).toBe('the_index_pattern');

const idxPattern4 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "the-index-pattern"');
expect(idxPattern4).toBe('the-index-pattern');

const idxPattern5 = getIndexPatternFromSQLQuery('SELECT woof, meow from "the-index-pattern"');
expect(idxPattern5).toBe('the-index-pattern');

const idxPattern6 = getIndexPatternFromSQLQuery('SELECT woof, meow from "logstash-*"');
expect(idxPattern6).toBe('logstash-*');

const idxPattern7 = getIndexPatternFromSQLQuery(
'SELECT woof, meow from logstash-1234! WHERE field > 100'
);
expect(idxPattern7).toBe('logstash-1234!');
});
});
});
37 changes: 37 additions & 0 deletions packages/kbn-es-query/src/es_query/es_query_sql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { Query, AggregateQuery } from '../filters';

// Checks if the query is of type Query
export function isOfQueryType(arg?: Query | AggregateQuery): arg is Query {
return Boolean(arg && 'query' in arg);
}

// Checks if the query is of type AggregateQuery
// currently only supports the sql query type
// should be enhanced to support other query types
export function isOfAggregateQueryType(query: AggregateQuery | Query): query is AggregateQuery {
return Boolean(query && 'sql' in query);
}

// returns the language of the aggregate Query, sql, esql etc
export function getAggregateQueryMode(query: AggregateQuery): string {
return Object.keys(query)[0];
}

// retrieves the index pattern from the aggregate query
export function getIndexPatternFromSQLQuery(sqlQuery?: string): string {
const sql = sqlQuery?.replaceAll('"', '').replaceAll("'", '');
// case insensitive match for the index pattern
const regex = new RegExp(/FROM\s+([\w*-.!@$^()~;]+)/, 'i');
const matches = sql?.match(regex);
if (matches) {
return matches[1];
}
return '';
}
6 changes: 6 additions & 0 deletions packages/kbn-es-query/src/es_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export { buildEsQuery } from './build_es_query';
export { buildQueryFromFilters } from './from_filters';
export { luceneStringToDsl } from './lucene_string_to_dsl';
export { decorateQuery } from './decorate_query';
export {
isOfQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
} from './es_query_sql';
export type {
IFieldSubType,
BoolQuery,
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-es-query/src/filters/build_filters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export type Query = {
language: string;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type AggregateQuery = {
sql?: string;
esql?: string;
};

/**
* An interface for a latitude-longitude pair
* @public
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export {

export type {
Query,
AggregateQuery,
Filter,
LatLon,
FieldFilter,
Expand Down
5 changes: 5 additions & 0 deletions packages/kbn-es-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type {
PhraseFilter,
PhrasesFilter,
Query,
AggregateQuery,
QueryStringFilter,
RangeFilter,
RangeFilterMeta,
Expand All @@ -52,6 +53,10 @@ export {
decorateQuery,
luceneStringToDsl,
migrateFilter,
isOfQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
} from './es_query';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { History } from 'history';
import { createQueryParamObservable } from '@kbn/kibana-utils-plugin/public';
import type { Query } from '@kbn/es-query';
import { DashboardAppLocatorParams, DashboardConstants } from '../..';
import { DashboardState } from '../../types';
import { getDashboardTitle } from '../../dashboard_strings';
Expand Down Expand Up @@ -113,7 +114,7 @@ function getLocatorParams({
timeRange: shouldRestoreSearchSession ? timefilter.getAbsoluteTime() : timefilter.getTime(),
searchSessionId: shouldRestoreSearchSession ? data.search.session.getSessionId() : undefined,
panels: getDashboardId() ? undefined : appState.panels,
query: queryString.formatQuery(appState.query),
query: queryString.formatQuery(appState.query) as Query,
filters: filterManager.getFilters(),
savedQuery: appState.savedQuery,
dashboardId: getDashboardId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import _ from 'lodash';
import { merge } from 'rxjs';
import { debounceTime, finalize, map, switchMap, tap } from 'rxjs/operators';

import { setQuery } from '../state';
import { DashboardBuildContext, DashboardState } from '../../types';
import { DashboardSavedObject } from '../../saved_dashboards';
Expand Down Expand Up @@ -100,7 +99,7 @@ export const syncDashboardFilterState = ({
// apply filters when the filter manager changes
const filterManagerSubscription = merge(filterManager.getUpdates$(), queryString.getUpdates$())
.pipe(debounceTime(100))
.subscribe(() => applyFilters(queryString.getQuery(), filterManager.getFilters()));
.subscribe(() => applyFilters(queryString.getQuery() as Query, filterManager.getFilters()));

const timeRefreshSubscription = merge(
timefilterService.getRefreshIntervalUpdate$(),
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/query/query_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { Filter } from '@kbn/es-query';
import type { TimeRange, RefreshInterval } from './timefilter/types';
import type { Query } from './types';
import type { Query, AggregateQuery } from './types';

/**
* All query state service state
Expand All @@ -22,5 +22,5 @@ export type QueryState = {
time?: TimeRange;
refreshInterval?: RefreshInterval;
filters?: Filter[];
query?: Query;
query?: Query | AggregateQuery;
};
Loading