Skip to content

Commit 30946fc

Browse files
Merge branch 'master' into build/docker-contexts
2 parents 4964102 + 198c6fb commit 30946fc

File tree

111 files changed

+1684
-657
lines changed

Some content is hidden

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

111 files changed

+1684
-657
lines changed

docs/developer/plugin-list.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ and actions.
370370
|The features plugin enhance Kibana with a per-feature privilege system.
371371
372372
373+
|{kib-repo}blob/{branch}/x-pack/plugins/file_upload[fileUpload]
374+
|WARNING: Missing README.
375+
376+
373377
|{kib-repo}blob/{branch}/x-pack/plugins/fleet/README.md[fleet]
374378
|Fleet needs to have Elasticsearch API keys enabled, and also to have TLS enabled on kibana, (if you want to run Kibana without TLS you can provide the following config flag --xpack.fleet.agents.tlsCheckDisabled=false)
375379

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.getfields.md

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,16 @@ returns all search source fields
99
<b>Signature:</b>
1010

1111
```typescript
12-
getFields(): {
13-
type?: string | undefined;
14-
query?: import("../..").Query | undefined;
15-
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
16-
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
17-
highlight?: any;
18-
highlightAll?: boolean | undefined;
19-
aggs?: any;
20-
from?: number | undefined;
21-
size?: number | undefined;
22-
source?: string | boolean | string[] | undefined;
23-
version?: boolean | undefined;
24-
fields?: SearchFieldValue[] | undefined;
25-
fieldsFromSource?: string | boolean | string[] | undefined;
26-
index?: import("../..").IndexPattern | undefined;
27-
searchAfter?: import("./types").EsQuerySearchAfter | undefined;
28-
timeout?: string | undefined;
29-
terminate_after?: number | undefined;
30-
};
12+
getFields(recurse?: boolean): SearchSourceFields;
3113
```
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| --- | --- | --- |
19+
| recurse | <code>boolean</code> | |
20+
3221
<b>Returns:</b>
3322

34-
`{
35-
type?: string | undefined;
36-
query?: import("../..").Query | undefined;
37-
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
38-
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
39-
highlight?: any;
40-
highlightAll?: boolean | undefined;
41-
aggs?: any;
42-
from?: number | undefined;
43-
size?: number | undefined;
44-
source?: string | boolean | string[] | undefined;
45-
version?: boolean | undefined;
46-
fields?: SearchFieldValue[] | undefined;
47-
fieldsFromSource?: string | boolean | string[] | undefined;
48-
index?: import("../..").IndexPattern | undefined;
49-
searchAfter?: import("./types").EsQuerySearchAfter | undefined;
50-
timeout?: string | undefined;
51-
terminate_after?: number | undefined;
52-
}`
23+
`SearchSourceFields`
5324

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.getserializedfields.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ serializes search source fields (which can later be passed to [ISearchStartSearc
99
<b>Signature:</b>
1010

1111
```typescript
12-
getSerializedFields(): SearchSourceFields;
12+
getSerializedFields(recurse?: boolean): SearchSourceFields;
1313
```
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| --- | --- | --- |
19+
| recurse | <code>boolean</code> | |
20+
1421
<b>Returns:</b>
1522

1623
`SearchSourceFields`

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export declare class SearchSource
3535
| [fetch(options)](./kibana-plugin-plugins-data-public.searchsource.fetch.md) | | Fetch this source and reject the returned Promise on error |
3636
| [fetch$(options)](./kibana-plugin-plugins-data-public.searchsource.fetch_.md) | | Fetch this source from Elasticsearch, returning an observable over the response(s) |
3737
| [getField(field, recurse)](./kibana-plugin-plugins-data-public.searchsource.getfield.md) | | Gets a single field from the fields |
38-
| [getFields()](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
38+
| [getFields(recurse)](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
3939
| [getId()](./kibana-plugin-plugins-data-public.searchsource.getid.md) | | returns search source id |
4040
| [getOwnField(field)](./kibana-plugin-plugins-data-public.searchsource.getownfield.md) | | Get the field from our own fields, don't traverse up the chain |
4141
| [getParent()](./kibana-plugin-plugins-data-public.searchsource.getparent.md) | | Get the parent of this SearchSource {<!-- -->undefined\|searchSource<!-- -->} |
4242
| [getSearchRequestBody()](./kibana-plugin-plugins-data-public.searchsource.getsearchrequestbody.md) | | Returns body contents of the search request, often referred as query DSL. |
43-
| [getSerializedFields()](./kibana-plugin-plugins-data-public.searchsource.getserializedfields.md) | | serializes search source fields (which can later be passed to [ISearchStartSearchSource](./kibana-plugin-plugins-data-public.isearchstartsearchsource.md)<!-- -->) |
43+
| [getSerializedFields(recurse)](./kibana-plugin-plugins-data-public.searchsource.getserializedfields.md) | | serializes search source fields (which can later be passed to [ISearchStartSearchSource](./kibana-plugin-plugins-data-public.isearchstartsearchsource.md)<!-- -->) |
4444
| [onRequestStart(handler)](./kibana-plugin-plugins-data-public.searchsource.onrequeststart.md) | | Add a handler that will be notified whenever requests start |
4545
| [removeField(field)](./kibana-plugin-plugins-data-public.searchsource.removefield.md) | | remove field |
4646
| [serialize()](./kibana-plugin-plugins-data-public.searchsource.serialize.md) | | Serializes the instance to a JSON string and a set of referenced objects. Use this method to get a representation of the search source which can be stored in a saved object.<!-- -->The references returned by this function can be mixed with other references in the same object, however make sure there are no name-collisions. The references will be named <code>kibanaSavedObjectMeta.searchSourceJSON.index</code> and <code>kibanaSavedObjectMeta.searchSourceJSON.filter[&lt;number&gt;].meta.index</code>.<!-- -->Using <code>createSearchSource</code>, the instance can be re-created. |

src/plugins/data/common/field_formats/field_formats_registry.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,28 @@ import { FormatFactory } from './utils';
2323
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../kbn_field_types/types';
2424
import { UI_SETTINGS } from '../constants';
2525
import { FieldFormatNotFoundError } from '../field_formats';
26+
import { SerializedFieldFormat } from '../../../expressions/common/types';
2627

2728
export class FieldFormatsRegistry {
2829
protected fieldFormats: Map<FieldFormatId, FieldFormatInstanceType> = new Map();
2930
protected defaultMap: Record<string, FieldFormatConfig> = {};
3031
protected metaParamsOptions: Record<string, any> = {};
3132
protected getConfig?: FieldFormatsGetConfigFn;
3233
// overriden on the public contract
33-
public deserialize: FormatFactory = () => {
34+
public deserialize: FormatFactory = (mapping?: SerializedFieldFormat) => {
35+
if (!mapping) {
36+
return new (FieldFormat.from(identity))();
37+
}
38+
39+
const { id, params = {} } = mapping;
40+
if (id) {
41+
const Format = this.getType(id);
42+
43+
if (Format) {
44+
return new Format(params, this.getConfig);
45+
}
46+
}
47+
3448
return new (FieldFormat.from(identity))();
3549
};
3650

src/plugins/data/common/search/search_source/normalize_sort_request.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ function normalize(
4949
}
5050
}
5151

52+
// FIXME: for unknown reason on the server this setting is serialized
53+
// https://github.com/elastic/kibana/issues/89902
54+
if (typeof defaultSortOptions === 'string') {
55+
defaultSortOptions = JSON.parse(defaultSortOptions);
56+
}
5257
// Don't include unmapped_type for _score field
5358
// eslint-disable-next-line @typescript-eslint/naming-convention
5459
const { unmapped_type, ...otherSortOptions } = defaultSortOptions;

src/plugins/data/common/search/search_source/search_source.test.ts

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,175 @@ describe('SearchSource', () => {
8080
});
8181
});
8282

83+
describe('#getFields()', () => {
84+
test('gets the value for the property', () => {
85+
searchSource.setField('aggs', 5);
86+
expect(searchSource.getFields()).toMatchInlineSnapshot(`
87+
Object {
88+
"aggs": 5,
89+
}
90+
`);
91+
});
92+
93+
test('recurses parents to get the entire filters: plain object filter', () => {
94+
const RECURSE = true;
95+
96+
const parent = new SearchSource({}, searchSourceDependencies);
97+
parent.setField('filter', [
98+
{
99+
meta: {
100+
index: 'd180cae0-60c3-11eb-8569-bd1f5ed24bc9',
101+
params: {},
102+
alias: null,
103+
disabled: false,
104+
negate: false,
105+
},
106+
query: {
107+
range: {
108+
'@date': {
109+
gte: '2016-01-27T18:11:05.010Z',
110+
lte: '2021-01-27T18:11:05.010Z',
111+
format: 'strict_date_optional_time',
112+
},
113+
},
114+
},
115+
},
116+
]);
117+
searchSource.setParent(parent);
118+
searchSource.setField('aggs', 5);
119+
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
120+
Object {
121+
"aggs": 5,
122+
"filter": Array [
123+
Object {
124+
"meta": Object {
125+
"alias": null,
126+
"disabled": false,
127+
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
128+
"negate": false,
129+
"params": Object {},
130+
},
131+
"query": Object {
132+
"range": Object {
133+
"@date": Object {
134+
"format": "strict_date_optional_time",
135+
"gte": "2016-01-27T18:11:05.010Z",
136+
"lte": "2021-01-27T18:11:05.010Z",
137+
},
138+
},
139+
},
140+
},
141+
],
142+
}
143+
`);
144+
145+
// calling twice gives the same result: no searchSources in the hierarchy were modified
146+
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
147+
Object {
148+
"aggs": 5,
149+
"filter": Array [
150+
Object {
151+
"meta": Object {
152+
"alias": null,
153+
"disabled": false,
154+
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
155+
"negate": false,
156+
"params": Object {},
157+
},
158+
"query": Object {
159+
"range": Object {
160+
"@date": Object {
161+
"format": "strict_date_optional_time",
162+
"gte": "2016-01-27T18:11:05.010Z",
163+
"lte": "2021-01-27T18:11:05.010Z",
164+
},
165+
},
166+
},
167+
},
168+
],
169+
}
170+
`);
171+
});
172+
173+
test('recurses parents to get the entire filters: function filter', () => {
174+
const RECURSE = true;
175+
176+
const parent = new SearchSource({}, searchSourceDependencies);
177+
parent.setField('filter', () => ({
178+
meta: {
179+
index: 'd180cae0-60c3-11eb-8569-bd1f5ed24bc9',
180+
params: {},
181+
alias: null,
182+
disabled: false,
183+
negate: false,
184+
},
185+
query: {
186+
range: {
187+
'@date': {
188+
gte: '2016-01-27T18:11:05.010Z',
189+
lte: '2021-01-27T18:11:05.010Z',
190+
format: 'strict_date_optional_time',
191+
},
192+
},
193+
},
194+
}));
195+
searchSource.setParent(parent);
196+
searchSource.setField('aggs', 5);
197+
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
198+
Object {
199+
"aggs": 5,
200+
"filter": Array [
201+
Object {
202+
"meta": Object {
203+
"alias": null,
204+
"disabled": false,
205+
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
206+
"negate": false,
207+
"params": Object {},
208+
},
209+
"query": Object {
210+
"range": Object {
211+
"@date": Object {
212+
"format": "strict_date_optional_time",
213+
"gte": "2016-01-27T18:11:05.010Z",
214+
"lte": "2021-01-27T18:11:05.010Z",
215+
},
216+
},
217+
},
218+
},
219+
],
220+
}
221+
`);
222+
223+
// calling twice gives the same result: no double-added filters
224+
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
225+
Object {
226+
"aggs": 5,
227+
"filter": Array [
228+
Object {
229+
"meta": Object {
230+
"alias": null,
231+
"disabled": false,
232+
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
233+
"negate": false,
234+
"params": Object {},
235+
},
236+
"query": Object {
237+
"range": Object {
238+
"@date": Object {
239+
"format": "strict_date_optional_time",
240+
"gte": "2016-01-27T18:11:05.010Z",
241+
"lte": "2021-01-27T18:11:05.010Z",
242+
},
243+
},
244+
},
245+
},
246+
],
247+
}
248+
`);
249+
});
250+
});
251+
83252
describe('#removeField()', () => {
84253
test('remove property', () => {
85254
searchSource = new SearchSource({}, searchSourceDependencies);
@@ -619,13 +788,13 @@ describe('SearchSource', () => {
619788
expect(JSON.parse(searchSourceJSON).from).toEqual(123456);
620789
});
621790

622-
test('should omit sort and size', () => {
791+
test('should omit size but not sort', () => {
623792
searchSource.setField('highlightAll', true);
624793
searchSource.setField('from', 123456);
625794
searchSource.setField('sort', { field: SortDirection.asc });
626795
searchSource.setField('size', 200);
627796
const { searchSourceJSON } = searchSource.serialize();
628-
expect(Object.keys(JSON.parse(searchSourceJSON))).toEqual(['highlightAll', 'from']);
797+
expect(Object.keys(JSON.parse(searchSourceJSON))).toEqual(['highlightAll', 'from', 'sort']);
629798
});
630799

631800
test('should serialize filters', () => {

src/plugins/data/common/search/search_source/search_source.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,49 @@ export class SearchSource {
172172
/**
173173
* returns all search source fields
174174
*/
175-
getFields() {
175+
getFields(recurse = false): SearchSourceFields {
176+
let thisFilter = this.fields.filter; // type is single value, array, or function
177+
if (thisFilter) {
178+
if (typeof thisFilter === 'function') {
179+
thisFilter = thisFilter() || []; // type is single value or array
180+
}
181+
182+
if (Array.isArray(thisFilter)) {
183+
thisFilter = [...thisFilter];
184+
} else {
185+
thisFilter = [thisFilter];
186+
}
187+
} else {
188+
thisFilter = [];
189+
}
190+
191+
if (recurse) {
192+
const parent = this.getParent();
193+
if (parent) {
194+
const parentFields = parent.getFields(recurse);
195+
196+
let parentFilter = parentFields.filter; // type is single value, array, or function
197+
if (parentFilter) {
198+
if (typeof parentFilter === 'function') {
199+
parentFilter = parentFilter() || []; // type is single value or array
200+
}
201+
202+
if (Array.isArray(parentFilter)) {
203+
thisFilter.push(...parentFilter);
204+
} else {
205+
thisFilter.push(parentFilter);
206+
}
207+
}
208+
209+
// add combined filters to the fields
210+
const thisFields = {
211+
...this.fields,
212+
filter: thisFilter,
213+
};
214+
215+
return { ...parentFields, ...thisFields };
216+
}
217+
}
176218
return { ...this.fields };
177219
}
178220

@@ -605,9 +647,8 @@ export class SearchSource {
605647
/**
606648
* serializes search source fields (which can later be passed to {@link ISearchStartSearchSource})
607649
*/
608-
public getSerializedFields() {
609-
const { filter: originalFilters, ...searchSourceFields } = omit(this.getFields(), [
610-
'sort',
650+
public getSerializedFields(recurse = false) {
651+
const { filter: originalFilters, ...searchSourceFields } = omit(this.getFields(recurse), [
611652
'size',
612653
]);
613654
let serializedSearchSourceFields: SearchSourceFields = {

0 commit comments

Comments
 (0)