[Visualize] Duplicated query filters in es request (#60106)
* [Visualize] Duplicated query filters in es request Closes: #59630 * Fix CI * fix CI * move uniq_filters to common * fix scripts/check_published_api_changes Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
fb8175816f
commit
a708d69f50
|
@ -44,8 +44,8 @@ esFilters: {
|
||||||
getPhraseFilterField: (filter: import("../common").PhraseFilter) => string;
|
getPhraseFilterField: (filter: import("../common").PhraseFilter) => string;
|
||||||
getPhraseFilterValue: (filter: import("../common").PhraseFilter) => string | number | boolean;
|
getPhraseFilterValue: (filter: import("../common").PhraseFilter) => string | number | boolean;
|
||||||
getDisplayValueFromFilter: typeof getDisplayValueFromFilter;
|
getDisplayValueFromFilter: typeof getDisplayValueFromFilter;
|
||||||
compareFilters: (first: import("../common").Filter | import("../common").Filter[], second: import("../common").Filter | import("../common").Filter[], comparatorOptions?: import("./query/filter_manager/lib/compare_filters").FilterCompareOptions) => boolean;
|
compareFilters: (first: import("../common").Filter | import("../common").Filter[], second: import("../common").Filter | import("../common").Filter[], comparatorOptions?: import("../common").FilterCompareOptions) => boolean;
|
||||||
COMPARE_ALL_OPTIONS: import("./query/filter_manager/lib/compare_filters").FilterCompareOptions;
|
COMPARE_ALL_OPTIONS: import("../common").FilterCompareOptions;
|
||||||
generateFilters: typeof generateFilters;
|
generateFilters: typeof generateFilters;
|
||||||
onlyDisabledFiltersChanged: (newFilters?: import("../common").Filter[] | undefined, oldFilters?: import("../common").Filter[] | undefined) => boolean;
|
onlyDisabledFiltersChanged: (newFilters?: import("../common").Filter[] | undefined, oldFilters?: import("../common").Filter[] | undefined) => boolean;
|
||||||
changeTimeFilter: typeof changeTimeFilter;
|
changeTimeFilter: typeof changeTimeFilter;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { compareFilters, COMPARE_ALL_OPTIONS } from './compare_filters';
|
import { compareFilters, COMPARE_ALL_OPTIONS } from './compare_filters';
|
||||||
import { buildEmptyFilter, buildQueryFilter, FilterStateStore } from '../../../../common';
|
import { buildEmptyFilter, buildQueryFilter, FilterStateStore } from '../../es_query';
|
||||||
|
|
||||||
describe('filter manager utilities', () => {
|
describe('filter manager utilities', () => {
|
||||||
describe('compare filters', () => {
|
describe('compare filters', () => {
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defaults, isEqual, omit, map } from 'lodash';
|
import { defaults, isEqual, omit, map } from 'lodash';
|
||||||
import { FilterMeta, Filter } from '../../../../common';
|
import { FilterMeta, Filter } from '../../es_query';
|
||||||
|
|
||||||
export interface FilterCompareOptions {
|
export interface FilterCompareOptions {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
|
@ -18,14 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { dedupFilters } from './dedup_filters';
|
import { dedupFilters } from './dedup_filters';
|
||||||
import {
|
import { Filter, buildRangeFilter, buildQueryFilter, FilterStateStore } from '../../es_query';
|
||||||
Filter,
|
import { IIndexPattern, IFieldType } from '../../index_patterns';
|
||||||
IIndexPattern,
|
|
||||||
IFieldType,
|
|
||||||
buildRangeFilter,
|
|
||||||
buildQueryFilter,
|
|
||||||
FilterStateStore,
|
|
||||||
} from '../../../../common';
|
|
||||||
|
|
||||||
describe('filter manager utilities', () => {
|
describe('filter manager utilities', () => {
|
||||||
let indexPattern: IIndexPattern;
|
let indexPattern: IIndexPattern;
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
import { filter, find } from 'lodash';
|
import { filter, find } from 'lodash';
|
||||||
import { compareFilters, FilterCompareOptions } from './compare_filters';
|
import { compareFilters, FilterCompareOptions } from './compare_filters';
|
||||||
import { Filter } from '../../../../common';
|
import { Filter } from '../../es_query';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine 2 filter collections, removing duplicates
|
* Combine 2 filter collections, removing duplicates
|
22
src/plugins/data/common/query/filter_manager/index.ts
Normal file
22
src/plugins/data/common/query/filter_manager/index.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* 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/LICENSE-2.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { dedupFilters } from './dedup_filters';
|
||||||
|
export { uniqFilters } from './uniq_filters';
|
||||||
|
export { compareFilters, COMPARE_ALL_OPTIONS, FilterCompareOptions } from './compare_filters';
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { uniqFilters } from './uniq_filters';
|
import { uniqFilters } from './uniq_filters';
|
||||||
import { buildQueryFilter, Filter, FilterStateStore } from '../../../../common';
|
import { buildQueryFilter, Filter, FilterStateStore } from '../../es_query';
|
||||||
|
|
||||||
describe('filter manager utilities', () => {
|
describe('filter manager utilities', () => {
|
||||||
describe('niqFilter', () => {
|
describe('niqFilter', () => {
|
|
@ -17,8 +17,8 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { each, union } from 'lodash';
|
import { each, union } from 'lodash';
|
||||||
|
import { Filter } from '../../es_query';
|
||||||
import { dedupFilters } from './dedup_filters';
|
import { dedupFilters } from './dedup_filters';
|
||||||
import { Filter } from '../../../../common';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove duplicate filters from an array of filters
|
* Remove duplicate filters from an array of filters
|
|
@ -17,4 +17,5 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export * from './filter_manager';
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|
|
@ -47,13 +47,13 @@ import {
|
||||||
isQueryStringFilter,
|
isQueryStringFilter,
|
||||||
isRangeFilter,
|
isRangeFilter,
|
||||||
toggleFilterNegated,
|
toggleFilterNegated,
|
||||||
|
compareFilters,
|
||||||
|
COMPARE_ALL_OPTIONS,
|
||||||
} from '../common';
|
} from '../common';
|
||||||
|
|
||||||
import { FilterLabel } from './ui/filter_bar';
|
import { FilterLabel } from './ui/filter_bar';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
compareFilters,
|
|
||||||
COMPARE_ALL_OPTIONS,
|
|
||||||
generateFilters,
|
generateFilters,
|
||||||
onlyDisabledFiltersChanged,
|
onlyDisabledFiltersChanged,
|
||||||
changeTimeFilter,
|
changeTimeFilter,
|
||||||
|
|
|
@ -362,8 +362,8 @@ export const esFilters: {
|
||||||
getPhraseFilterField: (filter: import("../common").PhraseFilter) => string;
|
getPhraseFilterField: (filter: import("../common").PhraseFilter) => string;
|
||||||
getPhraseFilterValue: (filter: import("../common").PhraseFilter) => string | number | boolean;
|
getPhraseFilterValue: (filter: import("../common").PhraseFilter) => string | number | boolean;
|
||||||
getDisplayValueFromFilter: typeof getDisplayValueFromFilter;
|
getDisplayValueFromFilter: typeof getDisplayValueFromFilter;
|
||||||
compareFilters: (first: import("../common").Filter | import("../common").Filter[], second: import("../common").Filter | import("../common").Filter[], comparatorOptions?: import("./query/filter_manager/lib/compare_filters").FilterCompareOptions) => boolean;
|
compareFilters: (first: import("../common").Filter | import("../common").Filter[], second: import("../common").Filter | import("../common").Filter[], comparatorOptions?: import("../common").FilterCompareOptions) => boolean;
|
||||||
COMPARE_ALL_OPTIONS: import("./query/filter_manager/lib/compare_filters").FilterCompareOptions;
|
COMPARE_ALL_OPTIONS: import("../common").FilterCompareOptions;
|
||||||
generateFilters: typeof generateFilters;
|
generateFilters: typeof generateFilters;
|
||||||
onlyDisabledFiltersChanged: (newFilters?: import("../common").Filter[] | undefined, oldFilters?: import("../common").Filter[] | undefined) => boolean;
|
onlyDisabledFiltersChanged: (newFilters?: import("../common").Filter[] | undefined, oldFilters?: import("../common").Filter[] | undefined) => boolean;
|
||||||
changeTimeFilter: typeof changeTimeFilter;
|
changeTimeFilter: typeof changeTimeFilter;
|
||||||
|
@ -1843,8 +1843,8 @@ export type TSearchStrategyProvider<T extends TStrategyTypes> = (context: ISearc
|
||||||
// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:34:33 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:33:33 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:38:1 - (ae-forgotten-export) The symbol "QueryStateChange" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:37:1 - (ae-forgotten-export) The symbol "QueryStateChange" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromEvent" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromEvent" needs to be exported by the entry point index.d.ts
|
||||||
// src/plugins/data/public/types.ts:60:5 - (ae-forgotten-export) The symbol "IndexPatternSelectProps" needs to be exported by the entry point index.d.ts
|
// src/plugins/data/public/types.ts:60:5 - (ae-forgotten-export) The symbol "IndexPatternSelectProps" needs to be exported by the entry point index.d.ts
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,19 @@ import { Subject } from 'rxjs';
|
||||||
|
|
||||||
import { IUiSettingsClient } from 'src/core/public';
|
import { IUiSettingsClient } from 'src/core/public';
|
||||||
|
|
||||||
import { COMPARE_ALL_OPTIONS, compareFilters } from './lib/compare_filters';
|
|
||||||
import { sortFilters } from './lib/sort_filters';
|
import { sortFilters } from './lib/sort_filters';
|
||||||
import { mapAndFlattenFilters } from './lib/map_and_flatten_filters';
|
import { mapAndFlattenFilters } from './lib/map_and_flatten_filters';
|
||||||
import { uniqFilters } from './lib/uniq_filters';
|
|
||||||
import { onlyDisabledFiltersChanged } from './lib/only_disabled';
|
import { onlyDisabledFiltersChanged } from './lib/only_disabled';
|
||||||
import { PartitionedFilters } from './types';
|
import { PartitionedFilters } from './types';
|
||||||
import { FilterStateStore, Filter, isFilterPinned } from '../../../common';
|
|
||||||
|
import {
|
||||||
|
FilterStateStore,
|
||||||
|
Filter,
|
||||||
|
uniqFilters,
|
||||||
|
isFilterPinned,
|
||||||
|
compareFilters,
|
||||||
|
COMPARE_ALL_OPTIONS,
|
||||||
|
} from '../../../common';
|
||||||
|
|
||||||
export class FilterManager {
|
export class FilterManager {
|
||||||
private filters: Filter[] = [];
|
private filters: Filter[] = [];
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
export { FilterManager } from './filter_manager';
|
export { FilterManager } from './filter_manager';
|
||||||
|
|
||||||
export { uniqFilters } from './lib/uniq_filters';
|
|
||||||
export { mapAndFlattenFilters } from './lib/map_and_flatten_filters';
|
export { mapAndFlattenFilters } from './lib/map_and_flatten_filters';
|
||||||
export { onlyDisabledFiltersChanged } from './lib/only_disabled';
|
export { onlyDisabledFiltersChanged } from './lib/only_disabled';
|
||||||
export { generateFilters } from './lib/generate_filters';
|
export { generateFilters } from './lib/generate_filters';
|
||||||
export { compareFilters, COMPARE_ALL_OPTIONS } from './lib/compare_filters';
|
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { filter } from 'lodash';
|
import { filter } from 'lodash';
|
||||||
import { Filter } from '../../../../common';
|
import { Filter, compareFilters, COMPARE_ALL_OPTIONS } from '../../../../common';
|
||||||
import { compareFilters, COMPARE_ALL_OPTIONS } from './compare_filters';
|
|
||||||
|
|
||||||
const isEnabled = (f: Filter) => f && f.meta && !f.meta.disabled;
|
const isEnabled = (f: Filter) => f && f.meta && !f.meta.disabled;
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,9 @@ import { Subscription } from 'rxjs';
|
||||||
import { filter, map } from 'rxjs/operators';
|
import { filter, map } from 'rxjs/operators';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { BaseStateContainer } from '../../../../kibana_utils/public';
|
import { BaseStateContainer } from '../../../../kibana_utils/public';
|
||||||
import { COMPARE_ALL_OPTIONS, compareFilters } from '../filter_manager/lib/compare_filters';
|
|
||||||
import { QuerySetup, QueryStart } from '../query_service';
|
import { QuerySetup, QueryStart } from '../query_service';
|
||||||
import { QueryState, QueryStateChange } from './types';
|
import { QueryState, QueryStateChange } from './types';
|
||||||
import { FilterStateStore } from '../../../common/es_query/filters';
|
import { FilterStateStore, COMPARE_ALL_OPTIONS, compareFilters } from '../../../common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to setup two-way syncing of global data and a state container
|
* Helper to setup two-way syncing of global data and a state container
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
import { map, tap } from 'rxjs/operators';
|
import { map, tap } from 'rxjs/operators';
|
||||||
import { TimefilterSetup } from '../timefilter';
|
import { TimefilterSetup } from '../timefilter';
|
||||||
import { COMPARE_ALL_OPTIONS, compareFilters, FilterManager } from '../filter_manager';
|
import { FilterManager } from '../filter_manager';
|
||||||
import { QueryState, QueryStateChange } from './index';
|
import { QueryState, QueryStateChange } from './index';
|
||||||
import { createStateContainer } from '../../../../kibana_utils/public';
|
import { createStateContainer } from '../../../../kibana_utils/public';
|
||||||
import { isFilterPinned } from '../../../common/es_query/filters';
|
import { isFilterPinned, compareFilters, COMPARE_ALL_OPTIONS } from '../../../common';
|
||||||
|
|
||||||
export function createQueryStateObservable({
|
export function createQueryStateObservable({
|
||||||
timefilter: { timefilter },
|
timefilter: { timefilter },
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
import { uniq } from 'lodash';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { ExpressionFunctionDefinition } from '../../expression_functions';
|
import { ExpressionFunctionDefinition } from '../../expression_functions';
|
||||||
import { KibanaContext } from '../../expression_types';
|
import { KibanaContext } from '../../expression_types';
|
||||||
|
import { Query, uniqFilters } from '../../../../data/common';
|
||||||
|
|
||||||
interface Arguments {
|
interface Arguments {
|
||||||
q?: string | null;
|
q?: string | null;
|
||||||
|
@ -35,6 +36,15 @@ export type ExpressionFunctionKibanaContext = ExpressionFunctionDefinition<
|
||||||
Promise<KibanaContext>
|
Promise<KibanaContext>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
const getParsedValue = (data: any, defaultValue: any) =>
|
||||||
|
typeof data === 'string' && data.length ? JSON.parse(data) || defaultValue : defaultValue;
|
||||||
|
|
||||||
|
const mergeQueries = (first: Query | Query[] = [], second: Query | Query[]) =>
|
||||||
|
uniq<Query>(
|
||||||
|
[...(Array.isArray(first) ? first : [first]), ...(Array.isArray(second) ? second : [second])],
|
||||||
|
(n: any) => JSON.stringify(n.query)
|
||||||
|
);
|
||||||
|
|
||||||
export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
|
export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
|
||||||
name: 'kibana_context',
|
name: 'kibana_context',
|
||||||
type: 'kibana_context',
|
type: 'kibana_context',
|
||||||
|
@ -75,9 +85,9 @@ export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async fn(input, args, { getSavedObject }) {
|
async fn(input, args, { getSavedObject }) {
|
||||||
const queryArg = args.q ? JSON.parse(args.q) : [];
|
const timeRange = getParsedValue(args.timeRange, input?.timeRange);
|
||||||
let queries = Array.isArray(queryArg) ? queryArg : [queryArg];
|
let queries = mergeQueries(input?.query, getParsedValue(args?.q, []));
|
||||||
let filters = args.filters ? JSON.parse(args.filters) : [];
|
let filters = [...(input?.filters || []), ...getParsedValue(args?.filters, [])];
|
||||||
|
|
||||||
if (args.savedSearchId) {
|
if (args.savedSearchId) {
|
||||||
if (typeof getSavedObject !== 'function') {
|
if (typeof getSavedObject !== 'function') {
|
||||||
|
@ -89,29 +99,20 @@ export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
|
||||||
}
|
}
|
||||||
const obj = await getSavedObject('search', args.savedSearchId);
|
const obj = await getSavedObject('search', args.savedSearchId);
|
||||||
const search = obj.attributes.kibanaSavedObjectMeta as { searchSourceJSON: string };
|
const search = obj.attributes.kibanaSavedObjectMeta as { searchSourceJSON: string };
|
||||||
const data = JSON.parse(search.searchSourceJSON) as { query: string; filter: any[] };
|
const { query, filter } = getParsedValue(search.searchSourceJSON, {});
|
||||||
queries = queries.concat(data.query);
|
|
||||||
filters = filters.concat(data.filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input && input.query) {
|
if (query) {
|
||||||
queries = queries.concat(input.query);
|
queries = mergeQueries(queries, query);
|
||||||
|
}
|
||||||
|
if (filter) {
|
||||||
|
filters = [...filters, ...(Array.isArray(filter) ? filter : [filter])];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input && input.filters) {
|
|
||||||
filters = filters.concat(input.filters).filter((f: any) => !f.meta.disabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeRange = args.timeRange
|
|
||||||
? JSON.parse(args.timeRange)
|
|
||||||
: input
|
|
||||||
? input.timeRange
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'kibana_context',
|
type: 'kibana_context',
|
||||||
query: queries,
|
query: queries,
|
||||||
filters,
|
filters: uniqFilters(filters).filter((f: any) => !f.meta?.disabled),
|
||||||
timeRange,
|
timeRange,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue