Skip to content

Commit dbecb51

Browse files
authored
Accept additional dynamic field values for index template (#150543)
Fixes #123809 ## Summary This PR adds support for the `'true'`, `'false'`, and `'runtime'` values for the `dynamic` field of index templates as they are [supported by Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/dynamic.html#dynamic-parameters). Before these changes, setting one of these values for the `dynamic` field would cause a `MultipleMappingsWarning` message when editing the Mappings section as described in the scenario in #123809. Regarding the string values `'true'` and `'false'`, according to elastic/elasticsearch-java#139, "Elasticsearch is lenient and happily accepts a string for boolean values", which is why we need to add support for these two values in Kibana. https://user-images.githubusercontent.com/59341489/217516509-88679c38-271c-4c7d-9145-27c7f9cfa8ca.mov ### Checklist - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 2774028 commit dbecb51

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

x-pack/plugins/index_management/public/application/components/mappings_editor/constants/parameters_definition.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,13 @@ export const PARAMETERS_DEFINITION: { [key in ParameterName]: ParameterDefinitio
683683
fieldConfig: {
684684
defaultValue: true,
685685
},
686-
schema: t.union([t.boolean, t.literal('strict')]),
686+
schema: t.union([
687+
t.boolean,
688+
t.literal('strict'),
689+
t.literal('true'),
690+
t.literal('false'),
691+
t.literal('runtime'),
692+
]),
687693
},
688694
dynamic_toggle: {
689695
fieldConfig: {

x-pack/plugins/index_management/public/application/components/mappings_editor/lib/mappings_validator.test.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe('Properties validator', () => {
329329
orientation: 'ccw',
330330
boost: 1.5,
331331
scaling_factor: 2.5,
332-
dynamic: 'strict', // true | false | 'strict' are allowed
332+
dynamic: 'strict', // true | false | 'strict' | 'true' | 'false' | 'runtime' are allowed
333333
enabled: true,
334334
format: 'strict_date_optional_time',
335335
analyzer: 'standard',
@@ -367,16 +367,39 @@ describe('Properties validator', () => {
367367
type: 'object',
368368
dynamic: false,
369369
},
370+
goodField4: {
371+
type: 'object',
372+
dynamic: 'true',
373+
},
374+
goodField5: {
375+
type: 'object',
376+
dynamic: 'false',
377+
},
378+
goodField6: {
379+
type: 'object',
380+
dynamic: 'runtime',
381+
},
370382
};
371383

372384
const { value, errors } = validateProperties(properties as any);
373385

374-
expect(Object.keys(value)).toEqual(['wrongField', 'goodField', 'goodField2', 'goodField3']);
386+
expect(Object.keys(value)).toEqual([
387+
'wrongField',
388+
'goodField',
389+
'goodField2',
390+
'goodField3',
391+
'goodField4',
392+
'goodField5',
393+
'goodField6',
394+
]);
375395

376396
expect(value.wrongField).toEqual({ type: 'text' }); // All parameters have been stripped out but the "type".
377397
expect(value.goodField).toEqual(properties.goodField); // All parameters are stil there.
378398
expect(value.goodField2).toEqual(properties.goodField2);
379399
expect(value.goodField3).toEqual(properties.goodField3);
400+
expect(value.goodField4).toEqual(properties.goodField4);
401+
expect(value.goodField5).toEqual(properties.goodField5);
402+
expect(value.goodField6).toEqual(properties.goodField6);
380403

381404
const allWrongParameters = Object.keys(properties.wrongField).filter((v) => v !== 'type');
382405
expect(errors).toEqual(

x-pack/plugins/index_management/public/application/components/mappings_editor/lib/mappings_validator.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,14 @@ export const mappingsConfigurationSchema = t.exact(
207207
t.partial({
208208
properties: t.UnknownRecord,
209209
runtime: t.UnknownRecord,
210-
dynamic: t.union([t.literal(true), t.literal(false), t.literal('strict')]),
210+
dynamic: t.union([
211+
t.literal(true),
212+
t.literal(false),
213+
t.literal('strict'),
214+
t.literal('true'),
215+
t.literal('false'),
216+
t.literal('runtime'),
217+
]),
211218
date_detection: t.boolean,
212219
numeric_detection: t.boolean,
213220
dynamic_date_formats: t.array(t.string),

0 commit comments

Comments
 (0)