Skip to content

Commit a3d2afd

Browse files
authored
Index patterns api - load field list on server (#82629) (#83021)
The server side index patterns api can now load the field list. Previously it would error if a field list refresh was required. The regular and rollup index pattern field list loading methods were merged. Rollup index patterns require additional functionality over regular index patterns when it comes to loading the field list, but this won't be necessary once rollups v2 is released.
1 parent 6825c27 commit a3d2afd

File tree

48 files changed

+484
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+484
-394
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Get field list by providing an index patttern (or spec)
99
<b>Signature:</b>
1010

1111
```typescript
12-
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise<any>;
12+
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any>;
1313
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Get field list by providing { pattern }
99
<b>Signature:</b>
1010

1111
```typescript
12-
getFieldsForWildcard: (options?: GetFieldsOptions) => Promise<any>;
12+
getFieldsForWildcard: (options: GetFieldsOptions) => Promise<any>;
1313
```

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export declare class IndexPatternsService
2626
| [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 |
2727
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
2828
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
29-
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
30-
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options?: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
29+
| [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) |
30+
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
3131
| [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
3232
| [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 |
3333
| [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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; [getCapabilitiesForRollupIndices](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md)
4+
5+
## getCapabilitiesForRollupIndices() function
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
export declare function getCapabilitiesForRollupIndices(indices: {
11+
[key: string]: any;
12+
}): {
13+
[key: string]: any;
14+
};
15+
```
16+
17+
## Parameters
18+
19+
| Parameter | Type | Description |
20+
| --- | --- | --- |
21+
| indices | <code>{</code><br/><code> [key: string]: any;</code><br/><code>}</code> | |
22+
23+
<b>Returns:</b>
24+
25+
`{
26+
[key: string]: any;
27+
}`
28+

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsfetcher.getfieldsforwildcard.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ getFieldsForWildcard(options: {
1515
fieldCapsOptions?: {
1616
allow_no_indices: boolean;
1717
};
18+
type?: string;
19+
rollupIndex?: string;
1820
}): Promise<FieldDescriptor[]>;
1921
```
2022

2123
## Parameters
2224

2325
| Parameter | Type | Description |
2426
| --- | --- | --- |
25-
| options | <code>{</code><br/><code> pattern: string &#124; string[];</code><br/><code> metaFields?: string[];</code><br/><code> fieldCapsOptions?: {</code><br/><code> allow_no_indices: boolean;</code><br/><code> };</code><br/><code> }</code> | |
27+
| options | <code>{</code><br/><code> pattern: string &#124; string[];</code><br/><code> metaFields?: string[];</code><br/><code> fieldCapsOptions?: {</code><br/><code> allow_no_indices: boolean;</code><br/><code> };</code><br/><code> type?: string;</code><br/><code> rollupIndex?: string;</code><br/><code> }</code> | |
2628

2729
<b>Returns:</b>
2830

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```typescript
1010
start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): {
11-
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise<IndexPatternsCommonService>;
11+
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
1212
};
1313
```
1414

@@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps):
2222
<b>Returns:</b>
2323

2424
`{
25-
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise<IndexPatternsCommonService>;
25+
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
2626
}`
2727

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
| Function | Description |
3030
| --- | --- |
31+
| [getCapabilitiesForRollupIndices(indices)](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) | |
3132
| [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
3233
| [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | |
3334
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | |
@@ -77,6 +78,7 @@
7778
| [esQuery](./kibana-plugin-plugins-data-server.esquery.md) | |
7879
| [fieldFormats](./kibana-plugin-plugins-data-server.fieldformats.md) | |
7980
| [indexPatterns](./kibana-plugin-plugins-data-server.indexpatterns.md) | |
81+
| [mergeCapabilitiesWithFields](./kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md) | |
8082
| [search](./kibana-plugin-plugins-data-server.search.md) | |
8183
| [UI\_SETTINGS](./kibana-plugin-plugins-data-server.ui_settings.md) | |
8284

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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; [mergeCapabilitiesWithFields](./kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md)
4+
5+
## mergeCapabilitiesWithFields variable
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
mergeCapabilitiesWithFields: (rollupIndexCapabilities: {
11+
[key: string]: any;
12+
}, fieldsFromFieldCapsApi: {
13+
[key: string]: any;
14+
}, previousFields?: FieldDescriptor[]) => FieldDescriptor[]
15+
```

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ start(core: CoreStart): {
1212
fieldFormatServiceFactory: (uiSettings: import("src/core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
1313
};
1414
indexPatterns: {
15-
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("src/core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">) => Promise<import("../common").IndexPatternsService>;
15+
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("src/core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">, elasticsearchClient: import("src/core/server").ElasticsearchClient) => Promise<import("../common").IndexPatternsService>;
1616
};
1717
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
1818
};
@@ -31,7 +31,7 @@ start(core: CoreStart): {
3131
fieldFormatServiceFactory: (uiSettings: import("src/core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
3232
};
3333
indexPatterns: {
34-
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("src/core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">) => Promise<import("../common").IndexPatternsService>;
34+
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("src/core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">, elasticsearchClient: import("src/core/server").ElasticsearchClient) => Promise<import("../common").IndexPatternsService>;
3535
};
3636
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
3737
}`

src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ export class IndexPatternsService {
103103
* Refresh cache of index pattern ids and titles
104104
*/
105105
private async refreshSavedObjectsCache() {
106-
this.savedObjectsCache = await this.savedObjectsClient.find<IndexPatternSavedObjectAttrs>({
106+
const so = await this.savedObjectsClient.find<IndexPatternSavedObjectAttrs>({
107107
type: 'index-pattern',
108108
fields: ['title'],
109109
perPage: 10000,
110110
});
111+
this.savedObjectsCache = so;
111112
}
112113

113114
/**
@@ -220,13 +221,13 @@ export class IndexPatternsService {
220221
* Get field list by providing { pattern }
221222
* @param options
222223
*/
223-
getFieldsForWildcard = async (options: GetFieldsOptions = {}) => {
224+
getFieldsForWildcard = async (options: GetFieldsOptions) => {
224225
const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS);
225226
return this.apiClient.getFieldsForWildcard({
226227
pattern: options.pattern,
227228
metaFields,
228229
type: options.type,
229-
params: options.params || {},
230+
rollupIndex: options.rollupIndex,
230231
});
231232
};
232233

@@ -236,13 +237,13 @@ export class IndexPatternsService {
236237
*/
237238
getFieldsForIndexPattern = async (
238239
indexPattern: IndexPattern | IndexPatternSpec,
239-
options: GetFieldsOptions = {}
240+
options?: GetFieldsOptions
240241
) =>
241242
this.getFieldsForWildcard({
242-
pattern: indexPattern.title as string,
243-
...options,
244243
type: indexPattern.type,
245-
params: indexPattern.typeMeta && indexPattern.typeMeta.params,
244+
rollupIndex: indexPattern?.typeMeta?.params?.rollup_index,
245+
...options,
246+
pattern: indexPattern.title as string,
246247
});
247248

248249
/**
@@ -379,10 +380,10 @@ export class IndexPatternsService {
379380
try {
380381
spec.fields = isFieldRefreshRequired
381382
? await this.refreshFieldSpecMap(spec.fields || {}, id, spec.title as string, {
382-
pattern: title,
383+
pattern: title as string,
383384
metaFields: await this.config.get(UI_SETTINGS.META_FIELDS),
384385
type,
385-
params: typeMeta && typeMeta.params,
386+
rollupIndex: typeMeta?.params?.rollupIndex,
386387
})
387388
: spec.fields;
388389
} catch (err) {

0 commit comments

Comments
 (0)