Skip to content

Commit 000552d

Browse files
committed
Disable fields added from unknown saved object types (#70951)
* Allow disabled: false SO field mappings * Disable fields for unknown SO types * Update everyone else's docs ;) * Address review comments * Add unit tests for disableUnknownTypeMappingFields()
1 parent 3cbaf33 commit 000552d

13 files changed

+258
-38
lines changed

docs/development/core/server/kibana-plugin-core-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
154154
| [SavedObjectsBulkUpdateResponse](./kibana-plugin-core-server.savedobjectsbulkupdateresponse.md) | |
155155
| [SavedObjectsClientProviderOptions](./kibana-plugin-core-server.savedobjectsclientprovideroptions.md) | Options to control the creation of the Saved Objects Client. |
156156
| [SavedObjectsClientWrapperOptions](./kibana-plugin-core-server.savedobjectsclientwrapperoptions.md) | Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance. |
157-
| [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation.<!-- -->Note: this type intentially doesn't include a type definition for defining the <code>dynamic</code> mapping parameter. Saved Object fields should always inherit the <code>dynamic: 'strict'</code> paramater. If you are unsure of the shape of your data use <code>type: 'object', enabled: false</code> instead. |
157+
| [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation. |
158158
| [SavedObjectsCoreFieldMapping](./kibana-plugin-core-server.savedobjectscorefieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation. |
159159
| [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md) | |
160160
| [SavedObjectsDeleteByNamespaceOptions](./kibana-plugin-core-server.savedobjectsdeletebynamespaceoptions.md) | |
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-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) &gt; [dynamic](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.dynamic.md)
4+
5+
## SavedObjectsComplexFieldMapping.dynamic property
6+
7+
The dynamic property of the mapping, either `false` or `'strict'`<!-- -->. If unspecified `dynamic: 'strict'` will be inherited from the top-level index mappings.
8+
9+
Note: To limit the number of mapping fields Saved Object types should \*never\* use `dynamic: true`<!-- -->.
10+
11+
<b>Signature:</b>
12+
13+
```typescript
14+
dynamic?: false | 'strict';
15+
```
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-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) &gt; [enabled](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.enabled.md)
4+
5+
## SavedObjectsComplexFieldMapping.enabled property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
enabled?: boolean;
11+
```

docs/development/core/server/kibana-plugin-core-server.savedobjectscomplexfieldmapping.md

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

77
See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation.
88

9-
Note: this type intentially doesn't include a type definition for defining the `dynamic` mapping parameter. Saved Object fields should always inherit the `dynamic: 'strict'` paramater. If you are unsure of the shape of your data use `type: 'object', enabled: false` instead.
10-
119
<b>Signature:</b>
1210

1311
```typescript
@@ -19,6 +17,8 @@ export interface SavedObjectsComplexFieldMapping
1917
| Property | Type | Description |
2018
| --- | --- | --- |
2119
| [doc\_values](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.doc_values.md) | <code>boolean</code> | |
20+
| [dynamic](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping, either <code>false</code> or <code>'strict'</code>. If unspecified <code>dynamic: 'strict'</code> will be inherited from the top-level index mappings.<!-- -->Note: To limit the number of mapping fields Saved Object types should \*never\* use <code>dynamic: true</code>. |
21+
| [enabled](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.enabled.md) | <code>boolean</code> | |
2222
| [properties](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.properties.md) | <code>SavedObjectsMappingProperties</code> | |
2323
| [type](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.type.md) | <code>string</code> | |
2424

docs/development/core/server/kibana-plugin-core-server.savedobjectscorefieldmapping.enabled.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/development/core/server/kibana-plugin-core-server.savedobjectscorefieldmapping.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface SavedObjectsCoreFieldMapping
1717
| Property | Type | Description |
1818
| --- | --- | --- |
1919
| [doc\_values](./kibana-plugin-core-server.savedobjectscorefieldmapping.doc_values.md) | <code>boolean</code> | |
20-
| [enabled](./kibana-plugin-core-server.savedobjectscorefieldmapping.enabled.md) | <code>boolean</code> | |
2120
| [fields](./kibana-plugin-core-server.savedobjectscorefieldmapping.fields.md) | <code>{</code><br/><code> [subfield: string]: {</code><br/><code> type: string;</code><br/><code> ignore_above?: number;</code><br/><code> };</code><br/><code> }</code> | |
2221
| [index](./kibana-plugin-core-server.savedobjectscorefieldmapping.index.md) | <code>boolean</code> | |
2322
| [null\_value](./kibana-plugin-core-server.savedobjectscorefieldmapping.null_value.md) | <code>number &#124; boolean &#124; string</code> | |

docs/development/core/server/kibana-plugin-core-server.savedobjectstypemappingdefinition.dynamic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## SavedObjectsTypeMappingDefinition.dynamic property
66

7-
The dynamic property of the mapping. either `false` or 'strict'. Defaults to `false`
7+
The dynamic property of the mapping, either `false` or `'strict'`<!-- -->. If unspecified `dynamic: 'strict'` will be inherited from the top-level index mappings.
88

99
<b>Signature:</b>
1010

docs/development/core/server/kibana-plugin-core-server.savedobjectstypemappingdefinition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ const typeDefinition: SavedObjectsTypeMappingDefinition = {
4141

4242
| Property | Type | Description |
4343
| --- | --- | --- |
44-
| [dynamic](./kibana-plugin-core-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping. either <code>false</code> or 'strict'. Defaults to <code>false</code> |
44+
| [dynamic](./kibana-plugin-core-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping, either <code>false</code> or <code>'strict'</code>. If unspecified <code>dynamic: 'strict'</code> will be inherited from the top-level index mappings. |
4545
| [properties](./kibana-plugin-core-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | The underlying properties of the type mapping |
4646

src/core/server/saved_objects/mappings/types.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
* @public
4646
*/
4747
export interface SavedObjectsTypeMappingDefinition {
48-
/** The dynamic property of the mapping. either `false` or 'strict'. Defaults to `false` */
48+
/** The dynamic property of the mapping, either `false` or `'strict'`. If
49+
* unspecified `dynamic: 'strict'` will be inherited from the top-level
50+
* index mappings. */
4951
dynamic?: false | 'strict';
5052
/** The underlying properties of the type mapping */
5153
properties: SavedObjectsMappingProperties;
@@ -134,7 +136,6 @@ export interface SavedObjectsCoreFieldMapping {
134136
null_value?: number | boolean | string;
135137
index?: boolean;
136138
doc_values?: boolean;
137-
enabled?: boolean;
138139
fields?: {
139140
[subfield: string]: {
140141
type: string;
@@ -146,14 +147,19 @@ export interface SavedObjectsCoreFieldMapping {
146147
/**
147148
* See {@link SavedObjectsFieldMapping} for documentation.
148149
*
149-
* Note: this type intentially doesn't include a type definition for defining
150-
* the `dynamic` mapping parameter. Saved Object fields should always inherit
151-
* the `dynamic: 'strict'` paramater. If you are unsure of the shape of your
152-
* data use `type: 'object', enabled: false` instead.
153-
*
154150
* @public
155151
*/
156152
export interface SavedObjectsComplexFieldMapping {
153+
/**
154+
* The dynamic property of the mapping, either `false` or `'strict'`. If
155+
* unspecified `dynamic: 'strict'` will be inherited from the top-level
156+
* index mappings.
157+
*
158+
* Note: To limit the number of mapping fields Saved Object types should
159+
* *never* use `dynamic: true`.
160+
*/
161+
dynamic?: false | 'strict';
162+
enabled?: boolean;
157163
doc_values?: boolean;
158164
type?: string;
159165
properties: SavedObjectsMappingProperties;

src/core/server/saved_objects/migrations/core/index_migrator.test.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('IndexMigrator', () => {
151151
);
152152
});
153153

154-
test('retains mappings from the previous index', async () => {
154+
test('retains unknown core field mappings from the previous index', async () => {
155155
const { callCluster } = testOpts;
156156

157157
testOpts.mappingProperties = { foo: { type: 'text' } };
@@ -162,7 +162,7 @@ describe('IndexMigrator', () => {
162162
aliases: {},
163163
mappings: {
164164
properties: {
165-
author: { type: 'text' },
165+
unknown_core_field: { type: 'text' },
166166
},
167167
},
168168
},
@@ -187,7 +187,66 @@ describe('IndexMigrator', () => {
187187
},
188188
},
189189
properties: {
190-
author: { type: 'text' },
190+
unknown_core_field: { type: 'text' },
191+
foo: { type: 'text' },
192+
migrationVersion: { dynamic: 'true', type: 'object' },
193+
namespace: { type: 'keyword' },
194+
namespaces: { type: 'keyword' },
195+
type: { type: 'keyword' },
196+
updated_at: { type: 'date' },
197+
references: {
198+
type: 'nested',
199+
properties: {
200+
name: { type: 'keyword' },
201+
type: { type: 'keyword' },
202+
id: { type: 'keyword' },
203+
},
204+
},
205+
},
206+
},
207+
settings: { number_of_shards: 1, auto_expand_replicas: '0-1' },
208+
},
209+
index: '.kibana_2',
210+
});
211+
});
212+
213+
test('disables complex field mappings from unknown types in the previous index', async () => {
214+
const { callCluster } = testOpts;
215+
216+
testOpts.mappingProperties = { foo: { type: 'text' } };
217+
218+
withIndex(callCluster, {
219+
index: {
220+
'.kibana_1': {
221+
aliases: {},
222+
mappings: {
223+
properties: {
224+
unknown_complex_field: { properties: { description: { type: 'text' } } },
225+
},
226+
},
227+
},
228+
},
229+
});
230+
231+
await new IndexMigrator(testOpts).migrate();
232+
233+
expect(callCluster).toHaveBeenCalledWith('indices.create', {
234+
body: {
235+
mappings: {
236+
dynamic: 'strict',
237+
_meta: {
238+
migrationMappingPropertyHashes: {
239+
foo: '625b32086eb1d1203564cf85062dd22e',
240+
migrationVersion: '4a1746014a75ade3a714e1db5763276f',
241+
namespace: '2f4316de49999235636386fe51dc06c1',
242+
namespaces: '2f4316de49999235636386fe51dc06c1',
243+
references: '7997cf5a56cc02bdc9c93361bde732b0',
244+
type: '2f4316de49999235636386fe51dc06c1',
245+
updated_at: '00da57df13e94e9d98437d13ace4bfe0',
246+
},
247+
},
248+
properties: {
249+
unknown_complex_field: { dynamic: false, properties: {} },
191250
foo: { type: 'text' },
192251
migrationVersion: { dynamic: 'true', type: 'object' },
193252
namespace: { type: 'keyword' },

0 commit comments

Comments
 (0)