Skip to content

Commit

Permalink
add docs. allwo to unset default pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed May 27, 2021
1 parent 512df5b commit c9f1a77
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 18 deletions.
9 changes: 6 additions & 3 deletions docs/api/index-patterns.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ The following index patterns APIs are available:
** <<index-patterns-api-create, Create index pattern API>> to create {kib} index pattern
** <<index-patterns-api-update, Update index pattern API>> to partially updated {kib} index pattern
** <<index-patterns-api-delete, Delete index pattern API>> to delete {kib} index pattern
* Default index pattern
** <<index-patterns-api-default-get, Get default index pattern API>> to retrieve a default index pattern
** <<index-patterns-api-default-set, Set default index pattern API>> to set a default index pattern
* Fields
** <<index-patterns-fields-api-update, Update index pattern field>> to change field metadata, such as `count`, `customLabel` and `format`.


** <<index-patterns-fields-api-update, Update index pattern field>> to change field metadata, such as `count`, `customLabel` and `format`

include::index-patterns/get.asciidoc[]
include::index-patterns/create.asciidoc[]
include::index-patterns/update.asciidoc[]
include::index-patterns/delete.asciidoc[]
include::index-patterns/default-get.asciidoc[]
include::index-patterns/default-set.asciidoc[]
include::index-patterns/update-fields.asciidoc[]
55 changes: 55 additions & 0 deletions docs/api/index-patterns/default-get.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[[index-patterns-api-default-get]]
=== Get default index pattern API
++++
<titleabbrev>Get default index pattern</titleabbrev>
++++

experimental[] Retrieve a default index pattern ID. Kibana UI uses default index pattern unless user picks a different one.

[[index-patterns-api-default-get-request]]
==== Request

`GET <kibana host>:<port>/api/index_patterns/default`

`GET <kibana host>:<port>/s/<space_id>/api/index_patterns/default`

[[index-patterns-api-default-get-params]]
==== Path parameters

`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.

[[index-patterns-api-default-get-codes]]
==== Response code

`200`::
Indicates a successful call.

[[index-patterns-api-default-get-example]]
==== Example

Retrieve the default index pattern id:

[source,sh]
--------------------------------------------------
$ curl -X GET api/index_patterns/default
--------------------------------------------------
// KIBANA

The API returns an ID of a default index pattern:

[source,sh]
--------------------------------------------------
{
"index_pattern_id": "..."
}
--------------------------------------------------

In case there is no default index pattern, the API returns:

[source,sh]
--------------------------------------------------
{
"index_pattern_id": null
}
--------------------------------------------------
84 changes: 84 additions & 0 deletions docs/api/index-patterns/default-set.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[[index-patterns-api-default-set]]
=== Set default index pattern API
++++
<titleabbrev>Set default index pattern</titleabbrev>
++++

experimental[] Set a default index pattern ID. Kibana UI will use default index pattern unless user picks a different one.
The API doesn't validate if given `index_pattern_id` is a valid id.

[[index-patterns-api-default-set-request]]
==== Request

`POST <kibana host>:<port>/api/index_patterns/default`

`POST <kibana host>:<port>/s/<space_id>/api/index_patterns/default`

[[index-patterns-api-default-set-params]]
==== Path parameters

`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.

[[index-patterns-api-default-set-body]]
==== Request body

`index_pattern_id`:: (Required, `string` or `null`) Sets a default index pattern id. Use `null` to unset a default index pattern.

`force`:: (Optional, boolean) Updates existing default index pattern id. The default is `false`.


[[index-patterns-api-default-set-codes]]
==== Response code

`200`::
Indicates a successful call.

[[index-patterns-api-default-set-example]]
==== Example

Set the default index pattern id if none is set:

[source,sh]
--------------------------------------------------
$ curl -X POST api/index_patterns/default
{
"index_pattern_id": "..."
}
--------------------------------------------------
// KIBANA


Upsert the default index pattern:

[source,sh]
--------------------------------------------------
$ curl -X POST api/index_patterns/default
{
"index_pattern_id": "...",
"force": true
}
--------------------------------------------------
// KIBANA

Unset the default index pattern:

[source,sh]
--------------------------------------------------
$ curl -X POST api/index_patterns/default
{
"index_pattern_id": null,
"force": true
}
--------------------------------------------------
// KIBANA

The API returns:

[source,sh]
--------------------------------------------------
{
"acknowledged": true
}
--------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## IndexPatternsService.getDefaultId property

Get default index pattern id

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export declare class IndexPatternsService
| [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | |
| [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
| [getIdsWithTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;Array&lt;{</code><br/><code> id: string;</code><br/><code> title: string;</code><br/><code> }&gt;&gt;</code> | Get list of index pattern ids with titles |
| [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
| [refreshFields](./kibana-plugin-plugins-data-public.indexpatternsservice.refreshfields.md) | | <code>(indexPattern: IndexPattern) =&gt; Promise&lt;void&gt;</code> | Refresh field list for a given index pattern |
| [savedObjectToSpec](./kibana-plugin-plugins-data-public.indexpatternsservice.savedobjecttospec.md) | | <code>(savedObject: SavedObject&lt;IndexPatternAttributes&gt;) =&gt; IndexPatternSpec</code> | Converts index pattern saved object to index pattern spec |
| [setDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.setdefault.md) | | <code>(id: string, force?: boolean) =&gt; Promise&lt;void&gt;</code> | Optionally set default index pattern, unless force = true |
| [setDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.setdefault.md) | | <code>(id: string &#124; null, force?: boolean) =&gt; Promise&lt;void&gt;</code> | Optionally set default index pattern, unless force = true |

## Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Optionally set default index pattern, unless force = true
<b>Signature:</b>

```typescript
setDefault: (id: string, force?: boolean) => Promise<void>;
setDefault: (id: string | null, force?: boolean) => Promise<void>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## IndexPatternsService.getDefaultId property

Get default index pattern id

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export declare class IndexPatternsService
| [get](./kibana-plugin-plugins-data-server.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-server.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | |
| [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-server.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-server.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getIds](./kibana-plugin-plugins-data-server.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
| [getIdsWithTitle](./kibana-plugin-plugins-data-server.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;Array&lt;{</code><br/><code> id: string;</code><br/><code> title: string;</code><br/><code> }&gt;&gt;</code> | Get list of index pattern ids with titles |
| [getTitles](./kibana-plugin-plugins-data-server.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
| [refreshFields](./kibana-plugin-plugins-data-server.indexpatternsservice.refreshfields.md) | | <code>(indexPattern: IndexPattern) =&gt; Promise&lt;void&gt;</code> | Refresh field list for a given index pattern |
| [savedObjectToSpec](./kibana-plugin-plugins-data-server.indexpatternsservice.savedobjecttospec.md) | | <code>(savedObject: SavedObject&lt;IndexPatternAttributes&gt;) =&gt; IndexPatternSpec</code> | Converts index pattern saved object to index pattern spec |
| [setDefault](./kibana-plugin-plugins-data-server.indexpatternsservice.setdefault.md) | | <code>(id: string, force?: boolean) =&gt; Promise&lt;void&gt;</code> | Optionally set default index pattern, unless force = true |
| [setDefault](./kibana-plugin-plugins-data-server.indexpatternsservice.setdefault.md) | | <code>(id: string &#124; null, force?: boolean) =&gt; Promise&lt;void&gt;</code> | Optionally set default index pattern, unless force = true |

## Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Optionally set default index pattern, unless force = true
<b>Signature:</b>

```typescript
setDefault: (id: string, force?: boolean) => Promise<void>;
setDefault: (id: string | null, force?: boolean) => Promise<void>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ export class IndexPatternsService {
return null;
};

/**
* Get default index pattern id
*/
getDefaultId = async (): Promise<string | null> => {
const defaultIndexPatternId = await this.config.get('defaultIndex');
return defaultIndexPatternId ?? null;
Expand All @@ -210,7 +213,7 @@ export class IndexPatternsService {
* @param id
* @param force
*/
setDefault = async (id: string, force = false) => {
setDefault = async (id: string | null, force = false) => {
if (force || !this.config.get('defaultIndex')) {
await this.config.set('defaultIndex', id);
}
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,6 @@ export class IndexPatternsService {
// (undocumented)
getCache: () => Promise<SavedObject<IndexPatternSavedObjectAttrs>[] | null | undefined>;
getDefault: () => Promise<IndexPattern | null>;
// (undocumented)
getDefaultId: () => Promise<string | null>;
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any>;
// Warning: (ae-forgotten-export) The symbol "GetFieldsOptions" needs to be exported by the entry point index.d.ts
Expand All @@ -1637,7 +1636,7 @@ export class IndexPatternsService {
getTitles: (refresh?: boolean) => Promise<string[]>;
refreshFields: (indexPattern: IndexPattern) => Promise<void>;
savedObjectToSpec: (savedObject: SavedObject<IndexPatternAttributes>) => IndexPatternSpec;
setDefault: (id: string, force?: boolean) => Promise<void>;
setDefault: (id: string | null, force?: boolean) => Promise<void>;
updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number, ignoreErrors?: boolean): Promise<void | Error>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export const registerManageDefaultIndexPatternRoutes = (
path: '/api/index_patterns/default',
validate: {
body: schema.object({
index_pattern_id: schema.string({
minLength: 1,
maxLength: 1_000,
}),
index_pattern_id: schema.nullable(
schema.string({
minLength: 1,
maxLength: 1_000,
})
),
force: schema.boolean({ defaultValue: false }),
}),
},
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ class IndexPatternsService {
// (undocumented)
getCache: () => Promise<SavedObject_2<IndexPatternSavedObjectAttrs>[] | null | undefined>;
getDefault: () => Promise<IndexPattern | null>;
// (undocumented)
getDefaultId: () => Promise<string | null>;
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any>;
// Warning: (ae-forgotten-export) The symbol "GetFieldsOptions" needs to be exported by the entry point index.d.ts
Expand All @@ -975,7 +974,7 @@ class IndexPatternsService {
getTitles: (refresh?: boolean) => Promise<string[]>;
refreshFields: (indexPattern: IndexPattern) => Promise<void>;
savedObjectToSpec: (savedObject: SavedObject_2<IndexPatternAttributes>) => IndexPatternSpec;
setDefault: (id: string, force?: boolean) => Promise<void>;
setDefault: (id: string | null, force?: boolean) => Promise<void>;
updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number, ignoreErrors?: boolean): Promise<void | Error>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export default function ({ getService }: FtrProviderContext) {
expect(response3.status).to.be(200);
const response4 = await supertest.get('/api/index_patterns/default');
expect(response4.body.index_pattern_id).to.be(defaultId); // original default id is used

const response5 = await supertest.post('/api/index_patterns/default').send({
index_pattern_id: null,
force: true,
});
expect(response5.status).to.be(200);

const response6 = await supertest.get('/api/index_patterns/default');
expect(response6.body.index_pattern_id).to.be(null);
});
});
}

0 comments on commit c9f1a77

Please sign in to comment.