Skip to content

Commit

Permalink
Address client/repository/types feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Feb 10, 2021
1 parent 740a8cd commit 669ab9e
Show file tree
Hide file tree
Showing 27 changed files with 179 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SavedObjectsFindOptions
| [namespaces](./kibana-plugin-core-public.savedobjectsfindoptions.namespaces.md) | <code>string[]</code> | |
| [page](./kibana-plugin-core-public.savedobjectsfindoptions.page.md) | <code>number</code> | |
| [perPage](./kibana-plugin-core-public.savedobjectsfindoptions.perpage.md) | <code>number</code> | |
| [pit](./kibana-plugin-core-public.savedobjectsfindoptions.pit.md) | <code>{</code><br/><code> id: string;</code><br/><code> keepAlive?: string;</code><br/><code> }</code> | Search against a specific Point In Time (PIT) that you've opened with <code>savedObjects.openPointInTimeForType</code>. |
| [pit](./kibana-plugin-core-public.savedobjectsfindoptions.pit.md) | <code>SavedObjectsPitParams</code> | Search against a specific Point In Time (PIT) that you've opened with . |
| [preference](./kibana-plugin-core-public.savedobjectsfindoptions.preference.md) | <code>string</code> | An optional ES preference value to be used for the query \* |
| [rootSearchFields](./kibana-plugin-core-public.savedobjectsfindoptions.rootsearchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. Unlike the <code>searchFields</code> argument, these are expected to be root fields and will not be modified. If used in conjunction with <code>searchFields</code>, both are concatenated together. |
| [search](./kibana-plugin-core-public.savedobjectsfindoptions.search.md) | <code>string</code> | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String <code>query</code> argument for more information |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

## SavedObjectsFindOptions.pit property

Search against a specific Point In Time (PIT) that you've opened with `savedObjects.openPointInTimeForType`<!-- -->.
Search against a specific Point In Time (PIT) that you've opened with .

<b>Signature:</b>

```typescript
pit?: {
id: string;
keepAlive?: string;
};
pit?: SavedObjectsPitParams;
```
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsMigrationVersion](./kibana-plugin-core-server.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [SavedObjectsOpenPointInTimeOptions](./kibana-plugin-core-server.savedobjectsopenpointintimeoptions.md) | |
| [SavedObjectsOpenPointInTimeResponse](./kibana-plugin-core-server.savedobjectsopenpointintimeresponse.md) | |
| [SavedObjectsPitParams](./kibana-plugin-core-server.savedobjectspitparams.md) | |
| [SavedObjectsRawDoc](./kibana-plugin-core-server.savedobjectsrawdoc.md) | A raw document as represented directly in the saved object index. |
| [SavedObjectsRawDocParseOptions](./kibana-plugin-core-server.savedobjectsrawdocparseoptions.md) | Options that can be specified when using the saved objects serializer to parse a raw document. |
| [SavedObjectsRemoveReferencesToOptions](./kibana-plugin-core-server.savedobjectsremovereferencestooptions.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SavedObjectsClient.closePointInTime() method

Closes a Point In Time (PIT) by ID. This simply proxies the request to ES via the Elasticsearch client, and is included in the Saved Objects Client as a convenience for consumers who are using `openPointInTimeForType`<!-- -->.
Closes a Point In Time (PIT) by ID. This simply proxies the request to ES via the Elasticsearch client, and is included in the Saved Objects Client as a convenience for consumers who are using [SavedObjectsClient.openPointInTimeForType()](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md)<!-- -->.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ The constructor for this class is marked as internal. Third-party code should no
| [bulkGet(objects, options)](./kibana-plugin-core-server.savedobjectsclient.bulkget.md) | | Returns an array of objects by id |
| [bulkUpdate(objects, options)](./kibana-plugin-core-server.savedobjectsclient.bulkupdate.md) | | Bulk Updates multiple SavedObject at once |
| [checkConflicts(objects, options)](./kibana-plugin-core-server.savedobjectsclient.checkconflicts.md) | | Check what conflicts will result when creating a given array of saved objects. This includes "unresolvable conflicts", which are multi-namespace objects that exist in a different namespace; such conflicts cannot be resolved/overwritten. |
| [closePointInTime(id, options)](./kibana-plugin-core-server.savedobjectsclient.closepointintime.md) | | Closes a Point In Time (PIT) by ID. This simply proxies the request to ES via the Elasticsearch client, and is included in the Saved Objects Client as a convenience for consumers who are using <code>openPointInTimeForType</code>. |
| [closePointInTime(id, options)](./kibana-plugin-core-server.savedobjectsclient.closepointintime.md) | | Closes a Point In Time (PIT) by ID. This simply proxies the request to ES via the Elasticsearch client, and is included in the Saved Objects Client as a convenience for consumers who are using [SavedObjectsClient.openPointInTimeForType()](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md)<!-- -->. |
| [create(type, attributes, options)](./kibana-plugin-core-server.savedobjectsclient.create.md) | | Persists a SavedObject |
| [delete(type, id, options)](./kibana-plugin-core-server.savedobjectsclient.delete.md) | | Deletes a SavedObject |
| [deleteFromNamespaces(type, id, namespaces, options)](./kibana-plugin-core-server.savedobjectsclient.deletefromnamespaces.md) | | Removes namespaces from a SavedObject |
| [find(options)](./kibana-plugin-core-server.savedobjectsclient.find.md) | | Find all SavedObjects matching the search query |
| [get(type, id, options)](./kibana-plugin-core-server.savedobjectsclient.get.md) | | Retrieves a single object |
| [openPointInTimeForType(type, options)](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md) | | Opens a Point In Time (PIT) against the indices for the specified Saved Object types. The returned <code>id</code> can then be passed to <code>SavedObjects.find</code> to search against that PIT. |
| [openPointInTimeForType(type, options)](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md) | | Opens a Point In Time (PIT) against the indices for the specified Saved Object types. The returned <code>id</code> can then be passed to [SavedObjectsClient.find()](./kibana-plugin-core-server.savedobjectsclient.find.md) to search against that PIT. |
| [removeReferencesTo(type, id, options)](./kibana-plugin-core-server.savedobjectsclient.removereferencesto.md) | | Updates all objects containing a reference to the given {<!-- -->type, id<!-- -->} tuple to remove the said reference. |
| [resolve(type, id, options)](./kibana-plugin-core-server.savedobjectsclient.resolve.md) | | Resolves a single object, using any legacy URL alias if it exists |
| [update(type, id, attributes, options)](./kibana-plugin-core-server.savedobjectsclient.update.md) | | Updates an SavedObject |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SavedObjectsClient.openPointInTimeForType() method

Opens a Point In Time (PIT) against the indices for the specified Saved Object types. The returned `id` can then be passed to `SavedObjects.find` to search against that PIT.
Opens a Point In Time (PIT) against the indices for the specified Saved Object types. The returned `id` can then be passed to [SavedObjectsClient.find()](./kibana-plugin-core-server.savedobjectsclient.find.md) to search against that PIT.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SavedObjectsFindOptions
| [namespaces](./kibana-plugin-core-server.savedobjectsfindoptions.namespaces.md) | <code>string[]</code> | |
| [page](./kibana-plugin-core-server.savedobjectsfindoptions.page.md) | <code>number</code> | |
| [perPage](./kibana-plugin-core-server.savedobjectsfindoptions.perpage.md) | <code>number</code> | |
| [pit](./kibana-plugin-core-server.savedobjectsfindoptions.pit.md) | <code>{</code><br/><code> id: string;</code><br/><code> keepAlive?: string;</code><br/><code> }</code> | Search against a specific Point In Time (PIT) that you've opened with <code>savedObjects.openPointInTimeForType</code>. |
| [pit](./kibana-plugin-core-server.savedobjectsfindoptions.pit.md) | <code>SavedObjectsPitParams</code> | Search against a specific Point In Time (PIT) that you've opened with [SavedObjectsClient.openPointInTimeForType()](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md)<!-- -->. |
| [preference](./kibana-plugin-core-server.savedobjectsfindoptions.preference.md) | <code>string</code> | An optional ES preference value to be used for the query \* |
| [rootSearchFields](./kibana-plugin-core-server.savedobjectsfindoptions.rootsearchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. Unlike the <code>searchFields</code> argument, these are expected to be root fields and will not be modified. If used in conjunction with <code>searchFields</code>, both are concatenated together. |
| [search](./kibana-plugin-core-server.savedobjectsfindoptions.search.md) | <code>string</code> | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String <code>query</code> argument for more information |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

## SavedObjectsFindOptions.pit property

Search against a specific Point In Time (PIT) that you've opened with `savedObjects.openPointInTimeForType`<!-- -->.
Search against a specific Point In Time (PIT) that you've opened with [SavedObjectsClient.openPointInTimeForType()](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md)<!-- -->.

<b>Signature:</b>

```typescript
pit?: {
id: string;
keepAlive?: string;
};
pit?: SavedObjectsPitParams;
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,31 @@ The Elasticsearch `sort` value of this result.
```typescript
sort?: unknown[];
```

## Remarks

This can be passed directly to the `searchAfter` param in the [SavedObjectsFindOptions](./kibana-plugin-core-server.savedobjectsfindoptions.md) in order to page through large numbers of hits. It is recommended you use this alongside a Point In Time (PIT) that was opened with [SavedObjectsClient.openPointInTimeForType()](./kibana-plugin-core-server.savedobjectsclient.openpointintimefortype.md)<!-- -->.

## Example


```ts
const { id } = await savedObjectsClient.openPointInTimeForType('visualization');
const page1 = await savedObjectsClient.find({
type: 'visualization',
sortField: 'updated_at',
sortOrder: 'asc',
pit,
});
const lastHit = page1.saved_objects[page1.saved_objects.length - 1];
const page2 = await savedObjectsClient.find({
type: 'visualization',
sortField: 'updated_at',
sortOrder: 'asc',
pit: { id: page1.pit_id },
searchAfter: lastHit.sort,
});
await savedObjectsClient.closePointInTime(page2.pit_id);

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsPitParams](./kibana-plugin-core-server.savedobjectspitparams.md) &gt; [id](./kibana-plugin-core-server.savedobjectspitparams.id.md)

## SavedObjectsPitParams.id property

<b>Signature:</b>

```typescript
id: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsPitParams](./kibana-plugin-core-server.savedobjectspitparams.md) &gt; [keepAlive](./kibana-plugin-core-server.savedobjectspitparams.keepalive.md)

## SavedObjectsPitParams.keepAlive property

<b>Signature:</b>

```typescript
keepAlive?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsPitParams](./kibana-plugin-core-server.savedobjectspitparams.md)

## SavedObjectsPitParams interface


<b>Signature:</b>

```typescript
export interface SavedObjectsPitParams
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [id](./kibana-plugin-core-server.savedobjectspitparams.id.md) | <code>string</code> | |
| [keepAlive](./kibana-plugin-core-server.savedobjectspitparams.keepalive.md) | <code>string</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ const { id } = await repository.openPointInTimeForType(
type: 'index-pattern',
{ keepAlive: '2m' },
);
const page1 = await savedObjectsClient.find({
type: 'visualization',
sortField: 'updated_at',
sortOrder: 'asc',
pit,
});

const response = await repository.find({
type: 'index-pattern',
search: 'foo*',
sortField: 'name',
sortOrder: 'desc',
pit: {
id: 'abc123',
keepAlive: '2m',
},
searchAfter: [1234, 'abcd'],
const lastHit = page1.saved_objects[page1.saved_objects.length - 1];
const page2 = await savedObjectsClient.find({
type: 'visualization',
sortField: 'updated_at',
sortOrder: 'asc',
pit: { id: page1.pit_id },
searchAfter: lastHit.sort,
});

await savedObjectsClient.closePointInTime(page2.pit_id);

```

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hits: {
highlight?: any;
inner_hits?: any;
matched_queries?: string[];
sort?: string[];
sort?: unknown[];
}>;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface SearchResponse<T = unknown>
| [\_scroll\_id](./kibana-plugin-core-server.searchresponse._scroll_id.md) | <code>string</code> | |
| [\_shards](./kibana-plugin-core-server.searchresponse._shards.md) | <code>ShardsResponse</code> | |
| [aggregations](./kibana-plugin-core-server.searchresponse.aggregations.md) | <code>any</code> | |
| [hits](./kibana-plugin-core-server.searchresponse.hits.md) | <code>{</code><br/><code> total: number;</code><br/><code> max_score: number;</code><br/><code> hits: Array&lt;{</code><br/><code> _index: string;</code><br/><code> _type: string;</code><br/><code> _id: string;</code><br/><code> _score: number;</code><br/><code> _source: T;</code><br/><code> _version?: number;</code><br/><code> _explanation?: Explanation;</code><br/><code> fields?: any;</code><br/><code> highlight?: any;</code><br/><code> inner_hits?: any;</code><br/><code> matched_queries?: string[];</code><br/><code> sort?: string[];</code><br/><code> }&gt;;</code><br/><code> }</code> | |
| [hits](./kibana-plugin-core-server.searchresponse.hits.md) | <code>{</code><br/><code> total: number;</code><br/><code> max_score: number;</code><br/><code> hits: Array&lt;{</code><br/><code> _index: string;</code><br/><code> _type: string;</code><br/><code> _id: string;</code><br/><code> _score: number;</code><br/><code> _source: T;</code><br/><code> _version?: number;</code><br/><code> _explanation?: Explanation;</code><br/><code> fields?: any;</code><br/><code> highlight?: any;</code><br/><code> inner_hits?: any;</code><br/><code> matched_queries?: string[];</code><br/><code> sort?: unknown[];</code><br/><code> }&gt;;</code><br/><code> }</code> | |
| [pit\_id](./kibana-plugin-core-server.searchresponse.pit_id.md) | <code>string</code> | |
| [timed\_out](./kibana-plugin-core-server.searchresponse.timed_out.md) | <code>boolean</code> | |
| [took](./kibana-plugin-core-server.searchresponse.took.md) | <code>number</code> | |
Expand Down
7 changes: 3 additions & 4 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1197,10 +1197,9 @@ export interface SavedObjectsFindOptions {
page?: number;
// (undocumented)
perPage?: number;
pit?: {
id: string;
keepAlive?: string;
};
// Warning: (ae-forgotten-export) The symbol "SavedObjectsPitParams" needs to be exported by the entry point index.d.ts
// Warning: (ae-unresolved-link) The @link reference could not be resolved: No member was found with name "openPointInTimeForType"
pit?: SavedObjectsPitParams;
preference?: string;
rootSearchFields?: string[];
search?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface SearchResponse<T = unknown> {
highlight?: any;
inner_hits?: any;
matched_queries?: string[];
sort?: string[];
sort?: unknown[];
}>;
};
aggregations?: any;
Expand Down
1 change: 1 addition & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export {
SavedObjectsClientContract,
SavedObjectsFindOptions,
SavedObjectsFindOptionsReference,
SavedObjectsPitParams,
SavedObjectsMigrationVersion,
} from './types';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export class SavedObjectsService
savedObjectsClient,
typeRegistry: this.typeRegistry,
exportSizeLimit: this.config!.maxImportExportSize,
logger: this.logger,
logger: this.logger.get('exporter'),
}),
createImporter: (savedObjectsClient) =>
new SavedObjectsImporter({
Expand Down
35 changes: 19 additions & 16 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,10 @@ export class SavedObjectsRepository {
(hit: SavedObjectsRawDoc): SavedObjectsFindResult => ({
...this._rawToSavedObject(hit),
score: (hit as any)._score,
...((hit as any).sort ? { sort: (hit as any).sort } : {}),
...((hit as any).sort && { sort: (hit as any).sort }),
})
),
...(body.pit_id ? { pit_id: body.pit_id } : {}),
...(body.pit_id && { pit_id: body.pit_id }),
} as SavedObjectsFindResponse<T>;
}

Expand Down Expand Up @@ -1794,18 +1794,23 @@ export class SavedObjectsRepository {
* type: 'index-pattern',
* { keepAlive: '2m' },
* );
* const page1 = await savedObjectsClient.find({
* type: 'visualization',
* sortField: 'updated_at',
* sortOrder: 'asc',
* pit,
* });
*
* const response = await repository.find({
* type: 'index-pattern',
* search: 'foo*',
* sortField: 'name',
* sortOrder: 'desc',
* pit: {
* id: 'abc123',
* keepAlive: '2m',
* },
* searchAfter: [1234, 'abcd'],
* const lastHit = page1.saved_objects[page1.saved_objects.length - 1];
* const page2 = await savedObjectsClient.find({
* type: 'visualization',
* sortField: 'updated_at',
* sortOrder: 'asc',
* pit: { id: page1.pit_id },
* searchAfter: lastHit.sort,
* });
*
* await savedObjectsClient.closePointInTime(page2.pit_id);
* ```
*
* @param {string|Array<string>} type
Expand All @@ -1816,10 +1821,8 @@ export class SavedObjectsRepository {
*/
async openPointInTimeForType(
type: string | string[],
{ keepAlive, preference }: SavedObjectsOpenPointInTimeOptions = {}
{ keepAlive = '5m', preference }: SavedObjectsOpenPointInTimeOptions = {}
): Promise<SavedObjectsOpenPointInTimeResponse> {
const defaultKeepAlive = '5m';

const types = Array.isArray(type) ? type : [type];
const allowedTypes = types.filter((t) => this._allowedTypes.includes(t));
if (allowedTypes.length === 0) {
Expand All @@ -1828,7 +1831,7 @@ export class SavedObjectsRepository {

const esOptions = {
index: this.getIndicesForTypes(allowedTypes),
keep_alive: keepAlive || defaultKeepAlive,
keep_alive: keepAlive,
...(preference ? { preference } : {}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* Side Public License, v 1.
*/

interface SavedObjectsPitParams {
id: string;
keepAlive?: string;
}
import { SavedObjectsPitParams } from '../../../types';

export function getPitParams(pit: SavedObjectsPitParams) {
return {
Expand Down
Loading

0 comments on commit 669ab9e

Please sign in to comment.