-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Index patterns] Default index pattern REST API (#100691)
- Loading branch information
Showing
18 changed files
with
347 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
-------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
-------------------------------------------------- | ||
|
13 changes: 13 additions & 0 deletions
13
...a/public/kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternsService](./kibana-plugin-plugins-data-public.indexpatternsservice.md) > [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md) | ||
|
||
## IndexPatternsService.getDefaultId property | ||
|
||
Get default index pattern id | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getDefaultId: () => Promise<string | null>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...a/server/kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) > [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md) | ||
|
||
## IndexPatternsService.getDefaultId property | ||
|
||
Get default index pattern id | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getDefaultId: () => Promise<string | null>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../server/kibana-plugin-plugins-data-server.searchstrategydependencies.request.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchStrategyDependencies](./kibana-plugin-plugins-data-server.searchstrategydependencies.md) > [request](./kibana-plugin-plugins-data-server.searchstrategydependencies.request.md) | ||
|
||
## SearchStrategyDependencies.request property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
request: KibanaRequest; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/plugins/data/server/index_patterns/routes/default_index_pattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { IRouter, StartServicesAccessor } from '../../../../../core/server'; | ||
import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; | ||
import { handleErrors } from './util/handle_errors'; | ||
|
||
export const registerManageDefaultIndexPatternRoutes = ( | ||
router: IRouter, | ||
getStartServices: StartServicesAccessor<DataPluginStartDependencies, DataPluginStart> | ||
) => { | ||
router.get( | ||
{ | ||
path: '/api/index_patterns/default', | ||
validate: {}, | ||
}, | ||
handleErrors(async (ctx, req, res) => { | ||
const savedObjectsClient = ctx.core.savedObjects.client; | ||
const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; | ||
const [, , { indexPatterns }] = await getStartServices(); | ||
const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( | ||
savedObjectsClient, | ||
elasticsearchClient | ||
); | ||
|
||
const defaultIndexPatternId = await indexPatternsService.getDefaultId(); | ||
|
||
return res.ok({ | ||
body: { | ||
index_pattern_id: defaultIndexPatternId, | ||
}, | ||
}); | ||
}) | ||
); | ||
|
||
router.post( | ||
{ | ||
path: '/api/index_patterns/default', | ||
validate: { | ||
body: schema.object({ | ||
index_pattern_id: schema.nullable( | ||
schema.string({ | ||
minLength: 1, | ||
maxLength: 1_000, | ||
}) | ||
), | ||
force: schema.boolean({ defaultValue: false }), | ||
}), | ||
}, | ||
}, | ||
handleErrors(async (ctx, req, res) => { | ||
const savedObjectsClient = ctx.core.savedObjects.client; | ||
const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; | ||
const [, , { indexPatterns }] = await getStartServices(); | ||
const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( | ||
savedObjectsClient, | ||
elasticsearchClient | ||
); | ||
|
||
const newDefaultId = req.body.index_pattern_id; | ||
const force = req.body.force; | ||
|
||
await indexPatternsService.setDefault(newDefaultId, force); | ||
|
||
return res.ok({ | ||
body: { | ||
acknowledged: true, | ||
}, | ||
}); | ||
}) | ||
); | ||
}; |
Oops, something went wrong.