Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
330131d
initial work on adding a saved query filter type
TinaHeiligers Sep 13, 2019
187a43b
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 16, 2019
a716ae6
Assumes the timefilter is already converted to an EsQuery in buildSav…
TinaHeiligers Sep 16, 2019
4233f49
adds unit test for saved_query builder
TinaHeiligers Sep 16, 2019
d3af1a7
adds timefilter to the filter array
TinaHeiligers Sep 16, 2019
898ca8c
Adds unit tests for different types of saved query objects
TinaHeiligers Sep 16, 2019
36815d1
Adds SavedQueryFilter types and duplicates all associated types decla…
TinaHeiligers Sep 17, 2019
2fcc2c5
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 17, 2019
a4d409d
removes index from buildSavedQueryFilter meta and adds mapping for sa…
TinaHeiligers Sep 17, 2019
03bf4df
Adds a test for a saved query type filter in map_filter
TinaHeiligers Sep 17, 2019
721cd27
Adds indexPattern to params in buildSavedQueryFilter and updates types
TinaHeiligers Sep 17, 2019
f73a4da
Updates test
TinaHeiligers Sep 17, 2019
56b7592
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 18, 2019
0a7293e
Toggles between creation and editing text depending on if we have a n…
TinaHeiligers Sep 18, 2019
42cdc6f
Converts useSavedQuery into a button, adds method to check if the fil…
TinaHeiligers Sep 18, 2019
3d77b37
Adds saved query filter pill display text case
TinaHeiligers Sep 18, 2019
101be52
uses nasty nested conditional to render different filter editors
TinaHeiligers Sep 18, 2019
d828c1a
Refactors nasty ternary
TinaHeiligers Sep 18, 2019
277c35b
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 19, 2019
23d1a69
Passes along the saved query service to the saved_query_editor
TinaHeiligers Sep 19, 2019
411c8cb
Passes along showSaveQuery boolean
TinaHeiligers Sep 19, 2019
e35927a
adds SavedQuery config param case to getFilterParams
TinaHeiligers Sep 19, 2019
a2cdb09
Fetches saved queries on rendering of the SavedQueryEditorUI
TinaHeiligers Sep 19, 2019
6b71d28
Enables selection of a saved query using the GenericComboBox
TinaHeiligers Sep 20, 2019
00d990a
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 20, 2019
20c216f
removed indexpattern and esQueryConfig from params, add them in befor…
TinaHeiligers Sep 20, 2019
b45365c
still have conflicting type comming in and going out for a saved quer…
TinaHeiligers Sep 20, 2019
190572b
Adds TODO's
TinaHeiligers Sep 20, 2019
8870fa7
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 21, 2019
852c8fe
gets saved queries on mounting
TinaHeiligers Sep 22, 2019
0c49154
changes function name
TinaHeiligers Sep 23, 2019
aef23c7
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 23, 2019
1849d78
slowly trying to replace hard coded options with SQ's
TinaHeiligers Sep 23, 2019
d33d867
Waits for saved queries to load before rendering list
TinaHeiligers Sep 23, 2019
6e5e496
passes selected option and all saved queries back to the editor
TinaHeiligers Sep 23, 2019
9832149
Calls change handler on saved query select directly
TinaHeiligers Sep 23, 2019
89bd899
fixes type issues
TinaHeiligers Sep 23, 2019
46ac6a2
undoes changes in ast
TinaHeiligers Sep 24, 2019
dd5e0e0
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 24, 2019
3c67fbe
Initial rework of saved query filters from building the dsl in the fi…
TinaHeiligers Sep 24, 2019
e1374b0
Adds saved query type but only one at a time, the saved query filters…
TinaHeiligers Sep 25, 2019
787250a
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 25, 2019
1ec4088
Fixes saved query filter tests
TinaHeiligers Sep 25, 2019
2ed2cb0
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 26, 2019
eb90387
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 27, 2019
7725a6e
Adds saved_query to filter for deduping omits saved_query from filter…
TinaHeiligers Sep 27, 2019
35e5c8b
Fixes props and type for FilterBar
TinaHeiligers Sep 27, 2019
70fc4d3
Refactors es-query saved_query filters to take in a full saved query …
TinaHeiligers Sep 27, 2019
aa22ec1
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 28, 2019
06ee9d2
Uses the full saved query to build the filter
TinaHeiligers Sep 28, 2019
124567a
Converts SavedQuerySingleSelect to functional component, renamed
TinaHeiligers Sep 28, 2019
a32c461
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Sep 30, 2019
782aa02
converts timefilter to ES range query
TinaHeiligers Sep 30, 2019
67ea38e
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 1, 2019
3472e1d
Adds comments to when the dsl from a savedQuery filter is actually cr…
TinaHeiligers Oct 1, 2019
d90874f
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 2, 2019
d5ff7fa
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 2, 2019
a8f12fa
Implements changing a saved query filter
TinaHeiligers Oct 2, 2019
ece6991
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 3, 2019
4c50d26
Recursively extracts and translates saved query filters
TinaHeiligers Oct 3, 2019
cd8ec3c
Adds saved query test to from_filters
TinaHeiligers Oct 3, 2019
3d10eb8
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 4, 2019
a4243fd
Adds test for translateToQuery
TinaHeiligers Oct 4, 2019
0eef346
Adds saved query filter tests to es_query
TinaHeiligers Oct 4, 2019
c762028
Unwraps bool from within query for a saved query filter
TinaHeiligers Oct 4, 2019
198e7e8
fixes types
TinaHeiligers Oct 4, 2019
2c28bad
Updates front end unit tests for saved query filters
TinaHeiligers Oct 5, 2019
4231372
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 7, 2019
1bff89f
Fixes some changes introduced by merged master
TinaHeiligers Oct 7, 2019
57aca94
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 8, 2019
b2f8e7f
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 9, 2019
47e7f06
Comments
TinaHeiligers Oct 9, 2019
1ab9aa4
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 10, 2019
ba1c33e
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 11, 2019
27c102a
removes spirulous 0
TinaHeiligers Oct 11, 2019
d787d31
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 14, 2019
7a2e286
removes commented out code
TinaHeiligers Oct 14, 2019
7b64c61
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 14, 2019
0787361
Initial work on using the search bar
TinaHeiligers Oct 15, 2019
6b5291a
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 15, 2019
b2f3082
Removes async from saved query filter mapper
TinaHeiligers Oct 15, 2019
5438820
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 15, 2019
16461df
Merge branch 'saved_query_filter_type_editable' into saved_query_filt…
TinaHeiligers Oct 15, 2019
09f9666
Uses stateless SearchBar component with props passed into it. We need…
TinaHeiligers Oct 15, 2019
8bae241
removes saved query service prop passed into the nested search bar
TinaHeiligers Oct 16, 2019
8bf4fcb
Merge branch 'master' of github.com:elastic/kibana into saved_query_f…
TinaHeiligers Oct 16, 2019
40e5234
[broken]:WIP changing filter meta params structure from nested in sav…
TinaHeiligers Oct 16, 2019
f99ca63
[broken] filters are not loading from a saved query in the search_bar…
TinaHeiligers Oct 16, 2019
368ed0d
Reverts changes on saved_query filter model
TinaHeiligers Oct 17, 2019
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
8 changes: 7 additions & 1 deletion packages/kbn-es-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildEsQuery(indexPattern, queries, filters, config)
Generates the Elasticsearch query DSL from combining the queries and filters provided.

```javascript
buildQueryFromFilters(filters, indexPattern)
buildQueryFromFilters(filters, indexPattern, ignoreFilterIfFieldNotInIndex, allowLeadingWildcards, queryStringOptions, dateFormatTZ)
```

Generates the Elasticsearch query DSL from the given filters.
Expand Down Expand Up @@ -72,6 +72,12 @@ buildRangeFilter(field, params, indexPattern)

Creates a filter (`RangeFilter`) where the value for the given field is in the given range. `params` should contain `lt`, `lte`, `gt`, and/or `gte`.

```javascript
buildSavedQueryFilter(savedQueryId)
```

Creates a filter (`SavedQueryFilter`) corresponding to a saved query. `params` should be an object containing the saved query.

## kuery

This folder contains the code corresponding to generating Elasticsearch queries using the Kibana query language.
Expand Down
65 changes: 65 additions & 0 deletions packages/kbn-es-query/src/es_query/__tests__/build_es_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,71 @@ describe('build query', function () {
expect(result).to.eql(expectedResult);
});

it('should build an Elasticsearch query from a saved query', function () {
const filters = {
meta: {
alias: null,
disabled: false,
key: 'Bytes more than 2000 onlu',
negate: false,
params: {
savedQuery: {
attributes: {
description: 'no filters at all',
query: {
language: 'kuery',
query: 'bytes >= 2000'
},
title: 'Bytes more than 2000 only',
},
id: 'Bytes more than 2000 only',
}
},
type: 'savedQuery',
value: undefined,
},
saved_query: 'Bytes more than 2000 only'
};
const config = {
allowLeadingWildcards: true,
queryStringOptions: {},
};
const expectedResult = {
bool: {
must: [],
filter: [
{
bool: {
must: [],
filter: [
{
bool: {
should: [
{
range: {
bytes: {
gte: 2000
}
}
}
],
minimum_should_match: 1
}
}
],
should: [],
must_not: []
}
}
],
should: [],
must_not: [],
}
};
const result = buildEsQuery(indexPattern, [], [filters], config);

expect(result).to.eql(expectedResult);
});
});

});
221 changes: 220 additions & 1 deletion packages/kbn-es-query/src/es_query/__tests__/from_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
* under the License.
*/


/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import expect from '@kbn/expect';
import { buildQueryFromFilters } from '../from_filters';
import { buildQueryFromFilters, translateToQuery } from '../from_filters';
import indexPattern from '../../__fixtures__/index_pattern_response.json';

describe('build query', function () {
describe('buildQueryFromFilters', function () {
Expand Down Expand Up @@ -121,5 +142,203 @@ describe('build query', function () {

expect(result.filter).to.eql(expectedESQueries);
});

it('should convert a saved query filter into an ES query', function () {
const savedQueryFilter = {
'$state': {
store: 'appState',
},
meta: {
alias: null,
disabled: false,
key: 'Bytes more than 2000 onlu',
negate: false,
params: {
savedQuery: {
attributes: {
description: 'no filters at all',
query: {
language: 'kuery',
query: 'bytes >= 2000'
},
title: 'Bytes more than 2000 only',
},
id: 'Bytes more than 2000 only',
}
},
type: 'savedQuery',
value: undefined,
},
saved_query: 'Bytes more than 2000 only'
};
const expectedESQueries = [
{
bool: {
must: [],
filter: [
{
bool: {
should: [
{
range: {
bytes: {
gte: 2000
}
}
}
],
minimum_should_match: 1
}
}
],
should: [],
must_not: []
}
}];
const result = buildQueryFromFilters([savedQueryFilter]);
expect(result.filter).to.eql(expectedESQueries);
});
});
describe('translateToQuery', function () {
it('should extract the contents of a saved query', function () {
const savedQueryFilter = {
'$state': {
store: 'appState',
},
meta: {
alias: null,
disabled: false,
key: 'Bytes more than 2000 only',
negate: false,
params: {
savedQuery: {
attributes: {
description: 'no filters at all',
query: {
language: 'kuery',
query: 'bytes >= 2000'
},
title: 'Bytes more than 2000 only',
},
id: 'Bytes more than 2000 only',
}
},
type: 'savedQuery',
value: undefined,
},
saved_query: 'Bytes more than 2000 only'
};
const expectedResult = {
bool: {
filter: [
{
bool: {
minimum_should_match: 1,
should: [{ range: { bytes: { gte: 2000 } } }],
}
}
],
must: [],
must_not: [],
should: [],
}
};
const result = translateToQuery(savedQueryFilter, { indexPattern });
expect(result).to.eql(expectedResult);
});

it('should extract and translate saved query filters that contain saved query filters', function () {
const savedQueryFilter = {
'$state': {
store: 'appState',
},
meta: {
alias: null,
disabled: false,
key: 'Compound',
negate: false,
params: {
savedQuery: {
attributes: {
description: 'Compound saved query',
filters: [
{
'$state': {
store: 'appState',
},
meta: {
alias: null,
disabled: false,
key: 'Ok response',
negate: false,
params: {
savedQuery: {
attributes: {
description: 'saved query',
query: {
language: 'kuery',
query: 'response.keyword: 200'
},
title: 'Ok response',
},
id: 'Ok response',
}
},
type: 'savedQuery',
value: undefined,
},
saved_query: 'Ok response'
}],
query: {
language: 'kuery',
query: ''
},
title: 'Compound',
},
id: 'Compound',
}
},
type: 'savedQuery',
value: undefined,
},
saved_query: 'Compound'
};
const expectedResult = {
bool: {
filter: [
{
match_all: {}
},
{
bool: {
filter: [
{
bool: {
minimum_should_match: 1,
should: [
{
match: {
'response.keyword': 200
}
}
]
}
}
],
must: [],
must_not: [],
should: [],
}
}
],
must: [],
must_not: [],
should: [],
}
};
const result = translateToQuery(savedQueryFilter, { indexPattern });
expect(result).to.eql(expectedResult);
});
});
});

9 changes: 8 additions & 1 deletion packages/kbn-es-query/src/es_query/build_es_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { buildQueryFromLucene } from './from_lucene';
* @param config - an objects with query:allowLeadingWildcards and query:queryString:options UI
* settings in form of { allowLeadingWildcards, queryStringOptions }
* config contains dateformat:tz
* @param allSavedQueries - an array of saved queries from which filters are built. Used in buildQueryFromFilters
*/
export function buildEsQuery(
indexPattern,
Expand All @@ -47,7 +48,13 @@ export function buildEsQuery(
const queriesByLanguage = groupBy(validQueries, 'language');
const kueryQuery = buildQueryFromKuery(indexPattern, queriesByLanguage.kuery, config.allowLeadingWildcards, config.dateFormatTZ);
const luceneQuery = buildQueryFromLucene(queriesByLanguage.lucene, config.queryStringOptions, config.dateFormatTZ);
const filterQuery = buildQueryFromFilters(filters, indexPattern, config.ignoreFilterIfFieldNotInIndex);
const filterQuery = buildQueryFromFilters(
filters,
indexPattern,
config.ignoreFilterIfFieldNotInIndex,
config.allowLeadingWildcards,
config.queryStringOptions,
config.dateFormatTZ);

return {
bool: {
Expand Down
Loading