Skip to content

Commit 1ceecd3

Browse files
authored
[Index patterns] Default index pattern REST API (#100691)
1 parent 57f59bd commit 1ceecd3

18 files changed

Lines changed: 347 additions & 11 deletions

docs/api/index-patterns.asciidoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ The following index patterns APIs are available:
1515
** <<index-patterns-api-create, Create index pattern API>> to create {kib} index pattern
1616
** <<index-patterns-api-update, Update index pattern API>> to partially updated {kib} index pattern
1717
** <<index-patterns-api-delete, Delete index pattern API>> to delete {kib} index pattern
18+
* Default index pattern
19+
** <<index-patterns-api-default-get, Get default index pattern API>> to retrieve a default index pattern
20+
** <<index-patterns-api-default-set, Set default index pattern API>> to set a default index pattern
1821
* Fields
19-
** <<index-patterns-fields-api-update, Update index pattern field>> to change field metadata, such as `count`, `customLabel` and `format`.
20-
21-
22+
** <<index-patterns-fields-api-update, Update index pattern field>> to change field metadata, such as `count`, `customLabel` and `format`
2223

2324
include::index-patterns/get.asciidoc[]
2425
include::index-patterns/create.asciidoc[]
2526
include::index-patterns/update.asciidoc[]
2627
include::index-patterns/delete.asciidoc[]
28+
include::index-patterns/default-get.asciidoc[]
29+
include::index-patterns/default-set.asciidoc[]
2730
include::index-patterns/update-fields.asciidoc[]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[[index-patterns-api-default-get]]
2+
=== Get default index pattern API
3+
++++
4+
<titleabbrev>Get default index pattern</titleabbrev>
5+
++++
6+
7+
experimental[] Retrieve a default index pattern ID. Kibana UI uses default index pattern unless user picks a different one.
8+
9+
[[index-patterns-api-default-get-request]]
10+
==== Request
11+
12+
`GET <kibana host>:<port>/api/index_patterns/default`
13+
14+
`GET <kibana host>:<port>/s/<space_id>/api/index_patterns/default`
15+
16+
[[index-patterns-api-default-get-params]]
17+
==== Path parameters
18+
19+
`space_id`::
20+
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.
21+
22+
[[index-patterns-api-default-get-codes]]
23+
==== Response code
24+
25+
`200`::
26+
Indicates a successful call.
27+
28+
[[index-patterns-api-default-get-example]]
29+
==== Example
30+
31+
Retrieve the default index pattern id:
32+
33+
[source,sh]
34+
--------------------------------------------------
35+
$ curl -X GET api/index_patterns/default
36+
--------------------------------------------------
37+
// KIBANA
38+
39+
The API returns an ID of a default index pattern:
40+
41+
[source,sh]
42+
--------------------------------------------------
43+
{
44+
"index_pattern_id": "..."
45+
}
46+
--------------------------------------------------
47+
48+
In case there is no default index pattern, the API returns:
49+
50+
[source,sh]
51+
--------------------------------------------------
52+
{
53+
"index_pattern_id": null
54+
}
55+
--------------------------------------------------
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[[index-patterns-api-default-set]]
2+
=== Set default index pattern API
3+
++++
4+
<titleabbrev>Set default index pattern</titleabbrev>
5+
++++
6+
7+
experimental[] Set a default index pattern ID. Kibana UI will use default index pattern unless user picks a different one.
8+
The API doesn't validate if given `index_pattern_id` is a valid id.
9+
10+
[[index-patterns-api-default-set-request]]
11+
==== Request
12+
13+
`POST <kibana host>:<port>/api/index_patterns/default`
14+
15+
`POST <kibana host>:<port>/s/<space_id>/api/index_patterns/default`
16+
17+
[[index-patterns-api-default-set-params]]
18+
==== Path parameters
19+
20+
`space_id`::
21+
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.
22+
23+
[[index-patterns-api-default-set-body]]
24+
==== Request body
25+
26+
`index_pattern_id`:: (Required, `string` or `null`) Sets a default index pattern id. Use `null` to unset a default index pattern.
27+
28+
`force`:: (Optional, boolean) Updates existing default index pattern id. The default is `false`.
29+
30+
31+
[[index-patterns-api-default-set-codes]]
32+
==== Response code
33+
34+
`200`::
35+
Indicates a successful call.
36+
37+
[[index-patterns-api-default-set-example]]
38+
==== Example
39+
40+
Set the default index pattern id if none is set:
41+
42+
[source,sh]
43+
--------------------------------------------------
44+
$ curl -X POST api/index_patterns/default
45+
{
46+
"index_pattern_id": "..."
47+
}
48+
--------------------------------------------------
49+
// KIBANA
50+
51+
52+
Upsert the default index pattern:
53+
54+
[source,sh]
55+
--------------------------------------------------
56+
$ curl -X POST api/index_patterns/default
57+
{
58+
"index_pattern_id": "...",
59+
"force": true
60+
}
61+
--------------------------------------------------
62+
// KIBANA
63+
64+
Unset the default index pattern:
65+
66+
[source,sh]
67+
--------------------------------------------------
68+
$ curl -X POST api/index_patterns/default
69+
{
70+
"index_pattern_id": null,
71+
"force": true
72+
}
73+
--------------------------------------------------
74+
// KIBANA
75+
76+
The API returns:
77+
78+
[source,sh]
79+
--------------------------------------------------
80+
{
81+
"acknowledged": true
82+
}
83+
--------------------------------------------------
84+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternsService](./kibana-plugin-plugins-data-public.indexpatternsservice.md) &gt; [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md)
4+
5+
## IndexPatternsService.getDefaultId property
6+
7+
Get default index pattern id
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
getDefaultId: () => Promise<string | null>;
13+
```

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export declare class IndexPatternsService
2727
| [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 |
2828
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
2929
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
30+
| [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
3031
| [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) |
3132
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
3233
| [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
3334
| [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 |
3435
| [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
3536
| [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 |
3637
| [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 |
37-
| [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 |
38+
| [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 |
3839

3940
## Methods
4041

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.setdefault.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Optionally set default index pattern, unless force = true
99
<b>Signature:</b>
1010

1111
```typescript
12-
setDefault: (id: string, force?: boolean) => Promise<void>;
12+
setDefault: (id: string | null, force?: boolean) => Promise<void>;
1313
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) &gt; [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md)
4+
5+
## IndexPatternsService.getDefaultId property
6+
7+
Get default index pattern id
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
getDefaultId: () => Promise<string | null>;
13+
```

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export declare class IndexPatternsService
2727
| [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 |
2828
| [getCache](./kibana-plugin-plugins-data-server.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
2929
| [getDefault](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
30+
| [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
3031
| [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) |
3132
| [getFieldsForWildcard](./kibana-plugin-plugins-data-server.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
3233
| [getIds](./kibana-plugin-plugins-data-server.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
3334
| [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 |
3435
| [getTitles](./kibana-plugin-plugins-data-server.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
3536
| [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 |
3637
| [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 |
37-
| [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 |
38+
| [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 |
3839

3940
## Methods
4041

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.setdefault.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Optionally set default index pattern, unless force = true
99
<b>Signature:</b>
1010

1111
```typescript
12-
setDefault: (id: string, force?: boolean) => Promise<void>;
12+
setDefault: (id: string | null, force?: boolean) => Promise<void>;
1313
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [SearchStrategyDependencies](./kibana-plugin-plugins-data-server.searchstrategydependencies.md) &gt; [request](./kibana-plugin-plugins-data-server.searchstrategydependencies.request.md)
4+
5+
## SearchStrategyDependencies.request property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
request: KibanaRequest;
11+
```

0 commit comments

Comments
 (0)