Skip to content

Commit

Permalink
Merge branch 'master' into ts-project-refs-es_ui/index_management
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Feb 2, 2021
2 parents 57ba4fa + 977fc6c commit 3f572af
Show file tree
Hide file tree
Showing 179 changed files with 3,242 additions and 2,800 deletions.
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ and actions.
|The features plugin enhance Kibana with a per-feature privilege system.
|{kib-repo}blob/{branch}/x-pack/plugins/file_upload[fileUpload]
|WARNING: Missing README.
|{kib-repo}blob/{branch}/x-pack/plugins/fleet/README.md[fleet]
|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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,16 @@ returns all search source fields
<b>Signature:</b>

```typescript
getFields(): {
type?: string | undefined;
query?: import("../..").Query | undefined;
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
highlight?: any;
highlightAll?: boolean | undefined;
aggs?: any;
from?: number | undefined;
size?: number | undefined;
source?: string | boolean | string[] | undefined;
version?: boolean | undefined;
fields?: SearchFieldValue[] | undefined;
fieldsFromSource?: string | boolean | string[] | undefined;
index?: import("../..").IndexPattern | undefined;
searchAfter?: import("./types").EsQuerySearchAfter | undefined;
timeout?: string | undefined;
terminate_after?: number | undefined;
};
getFields(recurse?: boolean): SearchSourceFields;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| recurse | <code>boolean</code> | |

<b>Returns:</b>

`{
type?: string | undefined;
query?: import("../..").Query | undefined;
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
highlight?: any;
highlightAll?: boolean | undefined;
aggs?: any;
from?: number | undefined;
size?: number | undefined;
source?: string | boolean | string[] | undefined;
version?: boolean | undefined;
fields?: SearchFieldValue[] | undefined;
fieldsFromSource?: string | boolean | string[] | undefined;
index?: import("../..").IndexPattern | undefined;
searchAfter?: import("./types").EsQuerySearchAfter | undefined;
timeout?: string | undefined;
terminate_after?: number | undefined;
}`
`SearchSourceFields`

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ serializes search source fields (which can later be passed to [ISearchStartSearc
<b>Signature:</b>

```typescript
getSerializedFields(): SearchSourceFields;
getSerializedFields(recurse?: boolean): SearchSourceFields;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| recurse | <code>boolean</code> | |

<b>Returns:</b>

`SearchSourceFields`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export declare class SearchSource
| [fetch(options)](./kibana-plugin-plugins-data-public.searchsource.fetch.md) | | Fetch this source and reject the returned Promise on error |
| [fetch$(options)](./kibana-plugin-plugins-data-public.searchsource.fetch_.md) | | Fetch this source from Elasticsearch, returning an observable over the response(s) |
| [getField(field, recurse)](./kibana-plugin-plugins-data-public.searchsource.getfield.md) | | Gets a single field from the fields |
| [getFields()](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
| [getFields(recurse)](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
| [getId()](./kibana-plugin-plugins-data-public.searchsource.getid.md) | | returns search source id |
| [getOwnField(field)](./kibana-plugin-plugins-data-public.searchsource.getownfield.md) | | Get the field from our own fields, don't traverse up the chain |
| [getParent()](./kibana-plugin-plugins-data-public.searchsource.getparent.md) | | Get the parent of this SearchSource {<!-- -->undefined\|searchSource<!-- -->} |
| [getSearchRequestBody()](./kibana-plugin-plugins-data-public.searchsource.getsearchrequestbody.md) | | Returns body contents of the search request, often referred as query DSL. |
| [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)<!-- -->) |
| [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)<!-- -->) |
| [onRequestStart(handler)](./kibana-plugin-plugins-data-public.searchsource.onrequeststart.md) | | Add a handler that will be notified whenever requests start |
| [removeField(field)](./kibana-plugin-plugins-data-public.searchsource.removefield.md) | | remove field |
| [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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { resolve } from 'path';
import execa from 'execa';
import expect from '@kbn/expect';
import shell from 'shelljs';

const ROOT_DIR = resolve(__dirname, '../../../../..');
Expand Down Expand Up @@ -38,11 +37,14 @@ describe('Team Assignment', () => {
describe(`when the codeowners file contains #CC#`, () => {
it(`should strip the prefix and still drill down through the fs`, async () => {
const { stdout } = await execa('grep', ['tre', teamAssignmentsPath], { cwd: ROOT_DIR });
expect(stdout).to.be(`x-pack/plugins/code/jest.config.js kibana-tre
x-pack/plugins/code/server/config.ts kibana-tre
x-pack/plugins/code/server/index.ts kibana-tre
x-pack/plugins/code/server/plugin.test.ts kibana-tre
x-pack/plugins/code/server/plugin.ts kibana-tre`);
const lines = stdout.split('\n').filter((line) => !line.includes('/target'));
expect(lines).toEqual([
'x-pack/plugins/code/jest.config.js kibana-tre',
'x-pack/plugins/code/server/config.ts kibana-tre',
'x-pack/plugins/code/server/index.ts kibana-tre',
'x-pack/plugins/code/server/plugin.test.ts kibana-tre',
'x-pack/plugins/code/server/plugin.ts kibana-tre',
]);
});
});
});
16 changes: 15 additions & 1 deletion src/plugins/data/common/field_formats/field_formats_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,28 @@ import { FormatFactory } from './utils';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../kbn_field_types/types';
import { UI_SETTINGS } from '../constants';
import { FieldFormatNotFoundError } from '../field_formats';
import { SerializedFieldFormat } from '../../../expressions/common/types';

export class FieldFormatsRegistry {
protected fieldFormats: Map<FieldFormatId, FieldFormatInstanceType> = new Map();
protected defaultMap: Record<string, FieldFormatConfig> = {};
protected metaParamsOptions: Record<string, any> = {};
protected getConfig?: FieldFormatsGetConfigFn;
// overriden on the public contract
public deserialize: FormatFactory = () => {
public deserialize: FormatFactory = (mapping?: SerializedFieldFormat) => {
if (!mapping) {
return new (FieldFormat.from(identity))();
}

const { id, params = {} } = mapping;
if (id) {
const Format = this.getType(id);

if (Format) {
return new Format(params, this.getConfig);
}
}

return new (FieldFormat.from(identity))();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ function normalize(
}
}

// FIXME: for unknown reason on the server this setting is serialized
// https://github.com/elastic/kibana/issues/89902
if (typeof defaultSortOptions === 'string') {
defaultSortOptions = JSON.parse(defaultSortOptions);
}
// Don't include unmapped_type for _score field
// eslint-disable-next-line @typescript-eslint/naming-convention
const { unmapped_type, ...otherSortOptions } = defaultSortOptions;
Expand Down
173 changes: 171 additions & 2 deletions src/plugins/data/common/search/search_source/search_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,175 @@ describe('SearchSource', () => {
});
});

describe('#getFields()', () => {
test('gets the value for the property', () => {
searchSource.setField('aggs', 5);
expect(searchSource.getFields()).toMatchInlineSnapshot(`
Object {
"aggs": 5,
}
`);
});

test('recurses parents to get the entire filters: plain object filter', () => {
const RECURSE = true;

const parent = new SearchSource({}, searchSourceDependencies);
parent.setField('filter', [
{
meta: {
index: 'd180cae0-60c3-11eb-8569-bd1f5ed24bc9',
params: {},
alias: null,
disabled: false,
negate: false,
},
query: {
range: {
'@date': {
gte: '2016-01-27T18:11:05.010Z',
lte: '2021-01-27T18:11:05.010Z',
format: 'strict_date_optional_time',
},
},
},
},
]);
searchSource.setParent(parent);
searchSource.setField('aggs', 5);
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
Object {
"aggs": 5,
"filter": Array [
Object {
"meta": Object {
"alias": null,
"disabled": false,
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
"negate": false,
"params": Object {},
},
"query": Object {
"range": Object {
"@date": Object {
"format": "strict_date_optional_time",
"gte": "2016-01-27T18:11:05.010Z",
"lte": "2021-01-27T18:11:05.010Z",
},
},
},
},
],
}
`);

// calling twice gives the same result: no searchSources in the hierarchy were modified
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
Object {
"aggs": 5,
"filter": Array [
Object {
"meta": Object {
"alias": null,
"disabled": false,
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
"negate": false,
"params": Object {},
},
"query": Object {
"range": Object {
"@date": Object {
"format": "strict_date_optional_time",
"gte": "2016-01-27T18:11:05.010Z",
"lte": "2021-01-27T18:11:05.010Z",
},
},
},
},
],
}
`);
});

test('recurses parents to get the entire filters: function filter', () => {
const RECURSE = true;

const parent = new SearchSource({}, searchSourceDependencies);
parent.setField('filter', () => ({
meta: {
index: 'd180cae0-60c3-11eb-8569-bd1f5ed24bc9',
params: {},
alias: null,
disabled: false,
negate: false,
},
query: {
range: {
'@date': {
gte: '2016-01-27T18:11:05.010Z',
lte: '2021-01-27T18:11:05.010Z',
format: 'strict_date_optional_time',
},
},
},
}));
searchSource.setParent(parent);
searchSource.setField('aggs', 5);
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
Object {
"aggs": 5,
"filter": Array [
Object {
"meta": Object {
"alias": null,
"disabled": false,
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
"negate": false,
"params": Object {},
},
"query": Object {
"range": Object {
"@date": Object {
"format": "strict_date_optional_time",
"gte": "2016-01-27T18:11:05.010Z",
"lte": "2021-01-27T18:11:05.010Z",
},
},
},
},
],
}
`);

// calling twice gives the same result: no double-added filters
expect(searchSource.getFields(RECURSE)).toMatchInlineSnapshot(`
Object {
"aggs": 5,
"filter": Array [
Object {
"meta": Object {
"alias": null,
"disabled": false,
"index": "d180cae0-60c3-11eb-8569-bd1f5ed24bc9",
"negate": false,
"params": Object {},
},
"query": Object {
"range": Object {
"@date": Object {
"format": "strict_date_optional_time",
"gte": "2016-01-27T18:11:05.010Z",
"lte": "2021-01-27T18:11:05.010Z",
},
},
},
},
],
}
`);
});
});

describe('#removeField()', () => {
test('remove property', () => {
searchSource = new SearchSource({}, searchSourceDependencies);
Expand Down Expand Up @@ -619,13 +788,13 @@ describe('SearchSource', () => {
expect(JSON.parse(searchSourceJSON).from).toEqual(123456);
});

test('should omit sort and size', () => {
test('should omit size but not sort', () => {
searchSource.setField('highlightAll', true);
searchSource.setField('from', 123456);
searchSource.setField('sort', { field: SortDirection.asc });
searchSource.setField('size', 200);
const { searchSourceJSON } = searchSource.serialize();
expect(Object.keys(JSON.parse(searchSourceJSON))).toEqual(['highlightAll', 'from']);
expect(Object.keys(JSON.parse(searchSourceJSON))).toEqual(['highlightAll', 'from', 'sort']);
});

test('should serialize filters', () => {
Expand Down
Loading

0 comments on commit 3f572af

Please sign in to comment.