[Maps] replace custom types with types from elasticsearch-js client (#132718)

* [Maps] replace custom types with types from elasticsearch-js client

* replace unknowns with types

* fix typings in AnomalySourceField

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2022-05-24 07:46:11 -06:00 committed by GitHub
parent 07bc517b75
commit 895220724f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 31 deletions

View file

@ -6,6 +6,11 @@
*/
import { DataView } from '@kbn/data-plugin/common';
import type {
AggregationsExtendedStatsAggregation,
AggregationsPercentilesAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { AGG_TYPE } from '../../../../common/constants';
import { TileMetaFeature } from '../../../../common/descriptor_types';
import { CountAggField } from './count_agg_field';
@ -97,17 +102,24 @@ export class AggField extends CountAggField {
return this._getAggType() === AGG_TYPE.TERMS ? TERMS_AGG_SHARD_SIZE : 0;
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
async getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null> {
return this._esDocField ? await this._esDocField.getExtendedStatsFieldMetaRequest() : null;
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null> {
async getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null> {
return this._esDocField
? await this._esDocField.getPercentilesFieldMetaRequest(percentiles)
: null;
}
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
async getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null> {
return this._esDocField ? await this._esDocField.getCategoricalFieldMetaRequest(size) : null;
}

View file

@ -5,6 +5,11 @@
* 2.0.
*/
import type {
AggregationsExtendedStatsAggregation,
AggregationsPercentilesAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { DataView } from '@kbn/data-plugin/common';
import { IESAggSource } from '../../sources/es_agg_source';
import { IVectorSource } from '../../sources/vector_source';
@ -100,15 +105,22 @@ export class CountAggField implements IESAggField {
return false;
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
async getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null> {
return null;
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null> {
async getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null> {
return null;
}
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
async getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null> {
return null;
}

View file

@ -82,15 +82,15 @@ export class TopTermPercentageField implements IESAggField {
return false;
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
async getExtendedStatsFieldMetaRequest(): Promise<null> {
return null;
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null> {
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<null> {
return null;
}
async getCategoricalFieldMetaRequest(): Promise<unknown> {
async getCategoricalFieldMetaRequest(): Promise<null> {
return null;
}

View file

@ -7,6 +7,11 @@
import type { IndexPatternField } from '@kbn/data-plugin/public';
import { indexPatterns } from '@kbn/data-plugin/public';
import type {
AggregationsExtendedStatsAggregation,
AggregationsPercentilesAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { FIELD_ORIGIN } from '../../../common/constants';
import { ESTooltipProperty } from '../tooltips/es_tooltip_property';
import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property';
@ -78,7 +83,10 @@ export class ESDocField extends AbstractField implements IField {
: super.getLabel();
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
async getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null> {
const indexPatternField = await this._getIndexPatternField();
if (
@ -88,10 +96,8 @@ export class ESDocField extends AbstractField implements IField {
return null;
}
// TODO remove local typing once Kibana has figured out a core place for Elasticsearch aggregation request types
// https://github.com/elastic/kibana/issues/60102
const metricAggConfig: { script?: unknown; field?: string } = {};
if (indexPatternField.scripted) {
const metricAggConfig: AggregationsExtendedStatsAggregation = {};
if (indexPatternField.scripted && indexPatternField.script) {
metricAggConfig.script = {
source: indexPatternField.script,
lang: indexPatternField.lang,
@ -106,17 +112,19 @@ export class ESDocField extends AbstractField implements IField {
};
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null> {
async getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null> {
const indexPatternField = await this._getIndexPatternField();
if (!indexPatternField || indexPatternField.type !== 'number') {
return null;
}
const metricAggConfig: { script?: unknown; field?: string; percents: number[] } = {
const metricAggConfig: AggregationsPercentilesAggregation = {
percents: [0, ...percentiles],
};
if (indexPatternField.scripted) {
if (indexPatternField.scripted && indexPatternField.script) {
metricAggConfig.script = {
source: indexPatternField.script,
lang: indexPatternField.lang,
@ -131,18 +139,18 @@ export class ESDocField extends AbstractField implements IField {
};
}
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
async getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null> {
const indexPatternField = await this._getIndexPatternField();
if (!indexPatternField || size <= 0) {
return null;
}
// TODO remove local typing once Kibana has figured out a core place for Elasticsearch aggregation request types
// https://github.com/elastic/kibana/issues/60102
const topTerms: { size: number; script?: unknown; field?: string } = {
const topTerms: AggregationsTermsAggregation = {
size: size - 1, // need additional color for the "other"-value
};
if (indexPatternField.scripted) {
if (indexPatternField.scripted && indexPatternField.script) {
topTerms.script = {
source: indexPatternField.script,
lang: indexPatternField.lang,

View file

@ -5,6 +5,11 @@
* 2.0.
*/
import type {
AggregationsExtendedStatsAggregation,
AggregationsPercentilesAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { TileMetaFeature } from '../../../common/descriptor_types';
import { FIELD_ORIGIN } from '../../../common/constants';
import { IVectorSource } from '../sources/vector_source';
@ -21,9 +26,16 @@ export interface IField {
getSource(): IVectorSource;
getOrigin(): FIELD_ORIGIN;
isValid(): boolean;
getExtendedStatsFieldMetaRequest(): Promise<unknown | null>;
getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null>;
getCategoricalFieldMetaRequest(size: number): Promise<unknown | null>;
getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null>;
getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null>;
getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null>;
/*
* IField.supportsFieldMetaFromLocalData returns boolean indicating whether field value domain
@ -107,15 +119,22 @@ export class AbstractField implements IField {
return this._origin;
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown> {
async getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null> {
return null;
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown | null> {
async getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null> {
return null;
}
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
async getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null> {
return null;
}

View file

@ -7,6 +7,11 @@
// eslint-disable-next-line max-classes-per-file
import React, { ReactNode } from 'react';
import type {
AggregationsExtendedStatsAggregation,
AggregationsPercentilesAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { escape } from 'lodash';
import { i18n } from '@kbn/i18n';
import { Filter } from '@kbn/es-query';
@ -230,15 +235,22 @@ export class AnomalySourceField implements IField {
return false;
}
async getExtendedStatsFieldMetaRequest(): Promise<unknown> {
async getExtendedStatsFieldMetaRequest(): Promise<Record<
string,
{ extended_stats: AggregationsExtendedStatsAggregation }
> | null> {
return null;
}
async getPercentilesFieldMetaRequest(percentiles: number[]): Promise<unknown> {
async getPercentilesFieldMetaRequest(
percentiles: number[]
): Promise<Record<string, { percentiles: AggregationsPercentilesAggregation }> | null> {
return null;
}
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
async getCategoricalFieldMetaRequest(
size: number
): Promise<Record<string, { terms: AggregationsTermsAggregation }> | null> {
return null;
}