Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into issue-119454-es…
Browse files Browse the repository at this point in the history
…-upgrade
  • Loading branch information
afharo committed Dec 22, 2021
2 parents cfdd8b3 + 3955d0d commit ae5ad9f
Show file tree
Hide file tree
Showing 162 changed files with 3,400 additions and 6,986 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@
"@types/kbn__server-http-tools": "link:bazel-bin/packages/kbn-server-http-tools/npm_module_types",
"@types/kbn__server-route-repository": "link:bazel-bin/packages/kbn-server-route-repository/npm_module_types",
"@types/kbn__std": "link:bazel-bin/packages/kbn-std/npm_module_types",
"@types/kbn__telemetry-tools": "link:bazel-bin/packages/kbn-telemetry-tools/npm_module_types",
"@types/license-checker": "15.0.0",
"@types/listr": "^0.14.0",
"@types/loader-utils": "^1.1.3",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ filegroup(
"//packages/kbn-server-http-tools:build_types",
"//packages/kbn-server-route-repository:build_types",
"//packages/kbn-std:build_types",
"//packages/kbn-telemetry-tools:build_types",
],
)

Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/build_es_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
import { Filter, Query } from '../filters';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';
import { KueryQueryOptions } from '../kuery';

/**
Expand Down Expand Up @@ -42,7 +42,7 @@ function removeMatchAll<T>(filters: T[]) {
* @public
*/
export function buildEsQuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queries: Query | Query[],
filters: Filter | Filter[],
config: EsQueryConfig = {
Expand Down
14 changes: 7 additions & 7 deletions packages/kbn-es-query/src/es_query/filter_matches_index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import { Filter } from '../filters';
import { filterMatchesIndex } from './filter_matches_index';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';

describe('filterMatchesIndex', () => {
it('should return true if the filter has no meta', () => {
const filter = {} as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
Expand All @@ -26,35 +26,35 @@ describe('filterMatchesIndex', () => {

it('should return true if the filter key matches a field name', () => {
const filter = { meta: { index: 'foo', key: 'bar' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});

it('should return true if custom filter for the same index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bara' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bara' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});

it('should return false if custom filter for a different index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'food', fields: [{ name: 'bara' }] } as IndexPatternBase;
const indexPattern = { id: 'food', fields: [{ name: 'bara' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});

it('should return false if the filter key does not match a field name', () => {
const filter = { meta: { index: 'foo', key: 'baz' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});

it('should return true if the filter has meta without a key', () => {
const filter = { meta: { index: 'foo' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/filter_matches_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Filter } from '../filters';
import { IndexPatternBase } from '..';
import { DataViewBase } from '..';

/*
* TODO: We should base this on something better than `filter.meta.key`. We should probably modify
Expand All @@ -16,7 +16,7 @@ import { IndexPatternBase } from '..';
*
* @internal
*/
export function filterMatchesIndex(filter: Filter, indexPattern?: IndexPatternBase | null) {
export function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {
if (!filter.meta?.key || !indexPattern) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/from_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { migrateFilter } from './migrate_filter';
import { filterMatchesIndex } from './filter_matches_index';
import { Filter, cleanFilter, isFilterDisabled } from '../filters';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';
import { handleNestedFilter } from './handle_nested_filter';

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ const translateToQuery = (filter: Partial<Filter>): estypes.QueryDslQueryContain
*/
export const buildQueryFromFilters = (
filters: Filter[] = [],
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
ignoreFilterIfFieldNotInIndex: boolean = false
): BoolQuery => {
filters = filters.filter((filter) => filter && !isFilterDisabled(filter));
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-es-query/src/es_query/from_kuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import { SerializableRecord } from '@kbn/utility-types';
import { Query } from '../filters';
import { fromKueryExpression, toElasticsearchQuery, nodeTypes, KueryNode } from '../kuery';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';

/** @internal */
export function buildQueryFromKuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queries: Query[] = [],
allowLeadingWildcards: boolean = false,
dateFormatTZ?: string,
Expand All @@ -27,7 +27,7 @@ export function buildQueryFromKuery(
}

function buildQuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queryASTs: KueryNode[],
config: SerializableRecord = {}
): BoolQuery {
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/handle_nested_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

import { getFilterField, cleanFilter, Filter } from '../filters';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';
import { getDataViewFieldSubtypeNested } from '../utils';

/** @internal */
export const handleNestedFilter = (filter: Filter, indexPattern?: IndexPatternBase) => {
export const handleNestedFilter = (filter: Filter, indexPattern?: DataViewBase) => {
if (!indexPattern) return filter;

const fieldName = getFilterField(filter);
Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-es-query/src/es_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export { buildQueryFromFilters } from './from_filters';
export { luceneStringToDsl } from './lucene_string_to_dsl';
export { decorateQuery } from './decorate_query';
export type {
IndexPatternBase,
IndexPatternFieldBase,
IFieldSubType,
BoolQuery,
DataViewBase,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/migrate_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { get, omit } from 'lodash';
import { getConvertedValueForField } from '../filters';
import { Filter } from '../filters';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';

/** @internal */
export interface DeprecatedMatchPhraseFilter extends Filter {
Expand All @@ -32,7 +32,7 @@ function isDeprecatedMatchPhraseFilter(filter: Filter): filter is DeprecatedMatc
}

/** @internal */
export function migrateFilter(filter: Filter, indexPattern?: IndexPatternBase) {
export function migrateFilter(filter: Filter, indexPattern?: DataViewBase) {
if (isDeprecatedMatchPhraseFilter(filter)) {
// @ts-ignore
const match = filter.match || filter.query.match;
Expand Down
10 changes: 0 additions & 10 deletions packages/kbn-es-query/src/es_query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ export interface DataViewFieldBase {
scripted?: boolean;
}

/**
* @deprecated Use DataViewField instead. All index pattern interfaces were renamed.
*/
export type IndexPatternFieldBase = DataViewFieldBase;

/**
* A base interface for an index pattern
* @public
Expand All @@ -68,11 +63,6 @@ export interface DataViewBase {
title: string;
}

/**
* @deprecated Use DataViewBase instead. All index pattern interfaces were renamed.
*/
export type IndexPatternBase = DataViewBase;

export interface BoolQuery {
must: estypes.QueryDslQueryContainer[];
must_not: estypes.QueryDslQueryContainer[];
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-es-query/src/filters/build_filters/build_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { buildPhrasesFilter } from './phrases_filter';
import { buildRangeFilter, RangeFilterParams } from './range_filter';
import { buildExistsFilter } from './exists_filter';

import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import { FilterStateStore } from './types';

/**
Expand All @@ -32,8 +32,8 @@ import { FilterStateStore } from './types';
* @public
*/
export function buildFilter(
indexPattern: IndexPatternBase,
field: IndexPatternFieldBase,
indexPattern: DataViewBase,
field: DataViewFieldBase,
type: FILTERS,
negate: boolean,
disabled: boolean,
Expand All @@ -52,8 +52,8 @@ export function buildFilter(
}

function buildBaseFilter(
indexPattern: IndexPatternBase,
field: IndexPatternFieldBase,
indexPattern: DataViewBase,
field: DataViewFieldBase,
type: FILTERS,
params: Serializable
): Filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { has } from 'lodash';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import type { Filter, FilterMeta } from './types';

/** @public */
Expand Down Expand Up @@ -44,7 +44,7 @@ export const getExistsFilterField = (filter: ExistsFilter) => {
*
* @public
*/
export const buildExistsFilter = (field: IndexPatternFieldBase, indexPattern: IndexPatternBase) => {
export const buildExistsFilter = (field: DataViewFieldBase, indexPattern: DataViewBase) => {
return {
meta: {
index: indexPattern.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { IndexPatternFieldBase } from '../../es_query';
import { DataViewFieldBase } from '../../es_query';

/**
* @internal
Expand All @@ -18,7 +18,7 @@ import { IndexPatternFieldBase } from '../../es_query';
* https://github.com/elastic/elasticsearch/pull/22201
**/
export const getConvertedValueForField = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
value: string | boolean | number
) => {
if (typeof value !== 'boolean' && field.type === 'boolean') {
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { get, has, isPlainObject } from 'lodash';
import type { Filter, FilterMeta } from './types';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import { getConvertedValueForField } from './get_converted_value_for_field';

export type PhraseFilterValue = string | number | boolean;
Expand Down Expand Up @@ -93,9 +93,9 @@ export const getPhraseFilterValue = (
* @public
*/
export const buildPhraseFilter = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
value: PhraseFilterValue,
indexPattern: IndexPatternBase
indexPattern: DataViewBase
): PhraseFilter | ScriptedPhraseFilter => {
const convertedValue = getConvertedValueForField(field, value);

Expand All @@ -117,7 +117,7 @@ export const buildPhraseFilter = (
};

/** @internal */
export const getPhraseScript = (field: IndexPatternFieldBase, value: PhraseFilterValue) => {
export const getPhraseScript = (field: DataViewFieldBase, value: PhraseFilterValue) => {
const convertedValue = getConvertedValueForField(field, value);
const script = buildInlineScriptForPhraseFilter(field);

Expand All @@ -141,7 +141,7 @@ export const getPhraseScript = (field: IndexPatternFieldBase, value: PhraseFilte
* @param {object} scriptedField A Field object representing a scripted field
* @returns {string} The inline script string
*/
export const buildInlineScriptForPhraseFilter = (scriptedField: IndexPatternFieldBase) => {
export const buildInlineScriptForPhraseFilter = (scriptedField: DataViewFieldBase) => {
// We must wrap painless scripts in a lambda in case they're more than a simple expression
if (scriptedField.lang === 'painless') {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { Filter, FilterMeta, FILTERS } from './types';
import { getPhraseScript, PhraseFilterValue } from './phrase_filter';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';

export type PhrasesFilterMeta = FilterMeta & {
params: PhraseFilterValue[]; // The unformatted values
Expand Down Expand Up @@ -48,9 +48,9 @@ export const getPhrasesFilterField = (filter: PhrasesFilter) => {
* @public
*/
export const buildPhrasesFilter = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
params: PhraseFilterValue[],
indexPattern: IndexPatternBase
indexPattern: DataViewBase
) => {
const index = indexPattern.id;
const type = FILTERS.PHRASES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { each } from 'lodash';
import { IndexPatternBase, IndexPatternFieldBase } from '../../es_query';
import { DataViewBase, DataViewFieldBase } from '../../es_query';
import { fields, getField } from '../stubs';
import {
buildRangeFilter,
Expand All @@ -17,12 +17,12 @@ import {
} from './range_filter';

describe('Range filter builder', () => {
let indexPattern: IndexPatternBase;
let indexPattern: DataViewBase;

beforeEach(() => {
indexPattern = {
id: 'id',
} as IndexPatternBase;
} as DataViewBase;
});

it('should be a function', () => {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Range filter builder', () => {
});

describe('when given params where one side is infinite', () => {
let field: IndexPatternFieldBase;
let field: DataViewFieldBase;
let filter: ScriptedRangeFilter;

beforeEach(() => {
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('Range filter builder', () => {
});

describe('when given params where both sides are infinite', () => {
let field: IndexPatternFieldBase;
let field: DataViewFieldBase;
let filter: ScriptedRangeFilter;

beforeEach(() => {
Expand Down Expand Up @@ -209,9 +209,9 @@ describe('Range filter builder', () => {
});

describe('getRangeFilterField', function () {
const indexPattern: IndexPatternBase = {
const indexPattern: DataViewBase = {
fields,
} as unknown as IndexPatternBase;
} as unknown as DataViewBase;

test('should return the name of the field a range query is targeting', () => {
const field = indexPattern.fields.find((patternField) => patternField.name === 'bytes');
Expand Down
Loading

0 comments on commit ae5ad9f

Please sign in to comment.