Skip to content

Commit cbd9804

Browse files
authored
Merge branch '7.x' into ua_reindexing_steps
2 parents 990dc0e + f1467bd commit cbd9804

194 files changed

Lines changed: 3882 additions & 1407 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ readonly links: {
241241
elasticAgent: string;
242242
datastreams: string;
243243
datastreamsNamingScheme: string;
244+
installElasticAgent: string;
244245
upgradeElasticAgent: string;
245246
upgradeElasticAgent712lower: string;
246247
learnMoreBlog: string;

docs/development/core/public/kibana-plugin-core-public.doclinksstart.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/core/public/doc_links/doc_links_service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,10 @@ export class DocLinksService {
484484
settings: `${FLEET_DOCS}fleet-settings.html#fleet-server-hosts-setting`,
485485
settingsFleetServerHostSettings: `${FLEET_DOCS}fleet-settings.html#fleet-server-hosts-setting`,
486486
troubleshooting: `${FLEET_DOCS}fleet-troubleshooting.html`,
487-
elasticAgent: `${FLEET_DOCS}elastic-agent-installation-configuration.html`,
487+
elasticAgent: `${FLEET_DOCS}elastic-agent-installation.html`,
488488
datastreams: `${FLEET_DOCS}data-streams.html`,
489489
datastreamsNamingScheme: `${FLEET_DOCS}data-streams.html#data-streams-naming-scheme`,
490+
installElasticAgent: `${FLEET_DOCS}install-fleet-managed-elastic-agent.html`,
490491
upgradeElasticAgent: `${FLEET_DOCS}upgrade-elastic-agent.html`,
491492
upgradeElasticAgent712lower: `${FLEET_DOCS}upgrade-elastic-agent.html#upgrade-7.12-lower`,
492493
learnMoreBlog: `${ELASTIC_WEBSITE_URL}blog/elastic-agent-and-fleet-make-it-easier-to-integrate-your-systems-with-elastic`,
@@ -751,6 +752,7 @@ export interface DocLinksStart {
751752
elasticAgent: string;
752753
datastreams: string;
753754
datastreamsNamingScheme: string;
755+
installElasticAgent: string;
754756
upgradeElasticAgent: string;
755757
upgradeElasticAgent712lower: string;
756758
learnMoreBlog: string;

src/core/public/public.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ export interface DocLinksStart {
711711
elasticAgent: string;
712712
datastreams: string;
713713
datastreamsNamingScheme: string;
714+
installElasticAgent: string;
714715
upgradeElasticAgent: string;
715716
upgradeElasticAgent712lower: string;
716717
learnMoreBlog: string;

src/plugins/data/common/search/aggs/metrics/single_percentile.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ describe('AggTypeMetricSinglePercentileProvider class', () => {
7373
).toEqual(123);
7474
});
7575

76+
it('should not throw error for empty buckets', () => {
77+
const agg = aggConfigs.getResponseAggs()[0];
78+
expect(agg.getValue({})).toEqual(NaN);
79+
});
80+
7681
it('produces the expected expression ast', () => {
7782
const agg = aggConfigs.getResponseAggs()[0];
7883
expect(agg.toExpressionAst()).toMatchInlineSnapshot(`

src/plugins/data/common/search/aggs/metrics/single_percentile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export const getSinglePercentileMetricAgg = () => {
5757
if (Number.isInteger(agg.params.percentile)) {
5858
valueKey += '.0';
5959
}
60-
return bucket[agg.id].values[valueKey];
60+
const { values } = bucket[agg.id] ?? {};
61+
62+
return values ? values[valueKey] : NaN;
6163
},
6264
});
6365
};

src/plugins/data/common/search/tabify/tabify_docs.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ function create(id: string) {
4141
});
4242
}
4343

44+
const meta = {
45+
_index: 'index-name',
46+
_id: '1',
47+
};
48+
4449
describe('tabify_docs', () => {
4550
describe('flattenHit', () => {
4651
let indexPattern: DataView;
@@ -70,6 +75,50 @@ describe('tabify_docs', () => {
7075
expect(Object.keys(response)).toEqual(expectedOrder);
7176
expect(Object.entries(response).map(([key]) => key)).toEqual(expectedOrder);
7277
});
78+
79+
it('does merge values from ignored_field_values and fields correctly', () => {
80+
const flatten = flattenHit(
81+
{
82+
...meta,
83+
fields: { 'extension.keyword': ['foo'], extension: ['foo', 'ignored'] },
84+
ignored_field_values: {
85+
'extension.keyword': ['ignored'],
86+
fully_ignored: ['some', 'value'],
87+
},
88+
},
89+
indexPattern,
90+
{ includeIgnoredValues: true }
91+
);
92+
expect(flatten).toHaveProperty(['extension.keyword'], ['foo', 'ignored']);
93+
expect(flatten).toHaveProperty('extension', ['foo', 'ignored']);
94+
expect(flatten).toHaveProperty('fully_ignored', ['some', 'value']);
95+
});
96+
97+
it('does not merge values from ignored_field_values into _source', () => {
98+
const flatten = flattenHit(
99+
{
100+
...meta,
101+
_source: { 'extension.keyword': ['foo', 'ignored'] },
102+
ignored_field_values: { 'extension.keyword': ['ignored'] },
103+
},
104+
indexPattern,
105+
{ includeIgnoredValues: true, source: true }
106+
);
107+
expect(flatten).toHaveProperty(['extension.keyword'], ['foo', 'ignored']);
108+
});
109+
110+
it('does merge ignored_field_values when no _source was present, even when parameter was on', () => {
111+
const flatten = flattenHit(
112+
{
113+
...meta,
114+
fields: { 'extension.keyword': ['foo'] },
115+
ignored_field_values: { 'extension.keyword': ['ignored'] },
116+
},
117+
indexPattern,
118+
{ includeIgnoredValues: true, source: true }
119+
);
120+
expect(flatten).toHaveProperty(['extension.keyword'], ['foo', 'ignored']);
121+
});
73122
});
74123

75124
describe('tabifyDocs', () => {

src/plugins/data/common/search/tabify/tabify_docs.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ export interface TabifyDocsOptions {
5555
* merged into the flattened document.
5656
*/
5757
source?: boolean;
58+
/**
59+
* If set to `true` values that have been ignored in ES (ignored_field_values)
60+
* will be merged into the flattened document. This will only have an effect if
61+
* the `hit` has been retrieved using the `fields` option.
62+
*/
63+
includeIgnoredValues?: boolean;
5864
}
5965

66+
// This is an overwrite of the SearchHit type to add the ignored_field_values.
67+
// Can be removed once the estypes.SearchHit knows about ignored_field_values
68+
type Hit<T = unknown> = estypes.SearchHit<T> & { ignored_field_values?: Record<string, unknown[]> };
69+
6070
/**
6171
* Flattens an individual hit (from an ES response) into an object. This will
6272
* create flattened field names, like `user.name`.
@@ -65,11 +75,7 @@ export interface TabifyDocsOptions {
6575
* @param indexPattern The index pattern for the requested index if available.
6676
* @param params Parameters how to flatten the hit
6777
*/
68-
export function flattenHit(
69-
hit: estypes.SearchHit,
70-
indexPattern?: IndexPattern,
71-
params?: TabifyDocsOptions
72-
) {
78+
export function flattenHit(hit: Hit, indexPattern?: IndexPattern, params?: TabifyDocsOptions) {
7379
const flat = {} as Record<string, any>;
7480

7581
function flatten(obj: Record<string, any>, keyPrefix: string = '') {
@@ -109,6 +115,28 @@ export function flattenHit(
109115
flatten(hit.fields || {});
110116
if (params?.source !== false && hit._source) {
111117
flatten(hit._source as Record<string, any>);
118+
} else if (params?.includeIgnoredValues && hit.ignored_field_values) {
119+
// If enabled merge the ignored_field_values into the flattened hit. This will
120+
// merge values that are not actually indexed by ES (i.e. ignored), e.g. because
121+
// they were above the `ignore_above` limit or malformed for specific types.
122+
// This API will only contain the values that were actually ignored, i.e. for the same
123+
// field there might exist another value in the `fields` response, why this logic
124+
// merged them both together. We do not merge this (even if enabled) in case source has been
125+
// merged, since we would otherwise duplicate values, since ignore_field_values and _source
126+
// contain the same values.
127+
Object.entries(hit.ignored_field_values).forEach(([fieldName, fieldValue]) => {
128+
if (flat[fieldName]) {
129+
// If there was already a value from the fields API, make sure we're merging both together
130+
if (Array.isArray(flat[fieldName])) {
131+
flat[fieldName] = [...flat[fieldName], ...fieldValue];
132+
} else {
133+
flat[fieldName] = [flat[fieldName], ...fieldValue];
134+
}
135+
} else {
136+
// If no previous value was assigned we can simply use the value from `ignored_field_values` as it is
137+
flat[fieldName] = fieldValue;
138+
}
139+
});
112140
}
113141

114142
// Merge all valid meta fields into the flattened object

src/plugins/data_views/common/data_views/data_view.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { DuplicateField } from '../../../kibana_utils/common';
1717

1818
import { IIndexPattern, IFieldType } from '../../common';
1919
import { DataViewField, IIndexPatternFieldList, fieldList } from '../fields';
20-
import { formatHitProvider } from './format_hit';
2120
import { flattenHitWrapper } from './flatten_hit';
2221
import {
2322
FieldFormatsStartCommon,
@@ -45,8 +44,6 @@ interface SavedObjectBody {
4544
type?: string;
4645
}
4746

48-
type FormatFieldFn = (hit: Record<string, any>, fieldName: string) => any;
49-
5047
export class DataView implements IIndexPattern {
5148
public id?: string;
5249
public title: string = '';
@@ -67,11 +64,6 @@ export class DataView implements IIndexPattern {
6764
* Type is used to identify rollup index patterns
6865
*/
6966
public type: string | undefined;
70-
public formatHit: {
71-
(hit: Record<string, any>, type?: string): any;
72-
formatField: FormatFieldFn;
73-
};
74-
public formatField: FormatFieldFn;
7567
/**
7668
* @deprecated Use `flattenHit` utility method exported from data plugin instead.
7769
*/
@@ -103,11 +95,6 @@ export class DataView implements IIndexPattern {
10395
this.fields = fieldList([], this.shortDotsEnable);
10496

10597
this.flattenHit = flattenHitWrapper(this, metaFields);
106-
this.formatHit = formatHitProvider(
107-
this,
108-
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING)
109-
);
110-
this.formatField = this.formatHit.formatField;
11198

11299
// set values
113100
this.id = spec.id;

src/plugins/data_views/common/data_views/format_hit.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)