Skip to content

Commit 37125f2

Browse files
authored
Adding index_template_substitutions to the simulate ingest API (elastic#114128) (elastic#114374)
This adds support for a new `index_template_substitutions` field to the body of an ingest simulate API request. These substitutions can be used to change the pipeline(s) used for ingest, or to change the mappings used for validation. It is similar to the `component_template_substitutions` added in elastic#113276. Here is an example that shows both of those usages working together: ``` ## First, add a couple of pipelines that set a field to a boolean: PUT /_ingest/pipeline/foo-pipeline?pretty { "processors": [ { "set": { "field": "foo", "value": true } } ] } PUT /_ingest/pipeline/bar-pipeline?pretty { "processors": [ { "set": { "field": "bar", "value": true } } ] } ## Now, create three component templates. One provides a mapping enforces that the only field is "foo" ## and that field is a keyword. The next is similar, but adds a `bar` field. The final one provides a setting ## that makes "foo-pipeline" the default pipeline. ## Remember that the "foo-pipeline" sets the "foo" field to a boolean, so using both of these templates ## together would cause a validation exception. These could be in the same template, but are provided ## separately just so that later we can show how multiple templates can be overridden. PUT _component_template/mappings_template { "template": { "mappings": { "dynamic": "strict", "properties": { "foo": { "type": "keyword" } } } } } PUT _component_template/mappings_template_with_bar { "template": { "mappings": { "dynamic": "strict", "properties": { "foo": { "type": "keyword" }, "bar": { "type": "boolean" } } } } } PUT _component_template/settings_template { "template": { "settings": { "index": { "default_pipeline": "foo-pipeline" } } } } ## Here we create an index template pulling in both of the component templates above PUT _index_template/template_1 { "index_patterns": ["foo*"], "composed_of": ["mappings_template", "settings_template"] } ## We can index a document here to create the index, or not. Either way the simulate call ought to work the same POST foo-1/_doc { "foo": "FOO" } ## This will not blow up with validation exceptions because the substitute "index_template_substitutions" ## uses `mappings_template_with_bar`, which adds the bar field. ## And the bar-pipeline is executed rather than the foo-pipeline because the substitute ## "index_template_substitutions" uses a substitute `settings_template`, so the value of "foo" ## does not get set to an invalid type. POST _ingest/_simulate?pretty&index=foo-1 { "docs": [ { "_id": "asdf", "_source": { "foo": "foo", "bar": "bar" } } ], "component_template_substitutions": { "settings_template": { "template": { "settings": { "index": { "default_pipeline": "bar-pipeline" } } } } }, "index_template_substitutions": { "template_1": { "index_patterns": ["foo*"], "composed_of": ["mappings_template_with_bar", "settings_template"] } } } ```
1 parent 80fb2ca commit 37125f2

File tree

16 files changed

+699
-67
lines changed

16 files changed

+699
-67
lines changed

docs/changelog/114128.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 114128
2+
summary: Adding `index_template_substitutions` to the simulate ingest API
3+
area: Ingest Node
4+
type: enhancement
5+
issues: []

docs/reference/indices/put-index-template.asciidoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout]
8585
[[put-index-template-api-request-body]]
8686
==== {api-request-body-title}
8787

88+
// tag::request-body[]
89+
8890
`composed_of`::
8991
(Optional, array of strings)
9092
An ordered list of component template names. Component templates are merged in the order
@@ -102,7 +104,7 @@ See <<create-index-template,create an index template>>.
102104
+
103105
.Properties of `data_stream`
104106
[%collapsible%open]
105-
====
107+
=====
106108
`allow_custom_routing`::
107109
(Optional, Boolean) If `true`, the data stream supports
108110
<<mapping-routing-field,custom routing>>. Defaults to `false`.
@@ -117,7 +119,7 @@ See <<create-index-template,create an index template>>.
117119
+
118120
If `time_series`, each backing index has an `index.mode` index setting of
119121
`time_series`.
120-
====
122+
=====
121123

122124
`index_patterns`::
123125
(Required, array of strings)
@@ -146,7 +148,7 @@ Template to be applied. It may optionally include an `aliases`, `mappings`, or
146148
+
147149
.Properties of `template`
148150
[%collapsible%open]
149-
====
151+
=====
150152
`aliases`::
151153
(Optional, object of objects) Aliases to add.
152154
+
@@ -161,7 +163,7 @@ include::{es-ref-dir}/indices/create-index.asciidoc[tag=aliases-props]
161163
include::{docdir}/rest-api/common-parms.asciidoc[tag=mappings]
162164
163165
include::{docdir}/rest-api/common-parms.asciidoc[tag=settings]
164-
====
166+
=====
165167

166168
`version`::
167169
(Optional, integer)
@@ -174,6 +176,7 @@ Marks this index template as deprecated.
174176
When creating or updating a non-deprecated index template that uses deprecated components,
175177
{es} will emit a deprecation warning.
176178
// end::index-template-api-body[]
179+
// end::request-body[]
177180

178181
[[put-index-template-api-example]]
179182
==== {api-examples-title}

docs/reference/ingest/apis/simulate-ingest.asciidoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,21 @@ POST /_ingest/_simulate
102102
}
103103
}
104104
}
105+
},
106+
"index_template_substitutions": { <3>
107+
"my-index-template": {
108+
"index_patterns": ["my-index-*"],
109+
"composed_of": ["component_template_1", "component_template_2"]
110+
}
105111
}
106112
}
107113
----
108114

109115
<1> This replaces the existing `my-pipeline` pipeline with the contents given here for the duration of this request.
110116
<2> This replaces the existing `my-component-template` component template with the contents given here for the duration of this request.
111117
These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
118+
<3> This replaces the existing `my-index-template` index template with the contents given here for the duration of this request.
119+
These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
112120

113121
[[simulate-ingest-api-request]]
114122
==== {api-request-title}
@@ -225,6 +233,19 @@ include::{es-ref-dir}/indices/put-component-template.asciidoc[tag=template]
225233
226234
====
227235

236+
`index_template_substitutions`::
237+
(Optional, map of strings to objects)
238+
Map of index template names to substitute index template definition objects.
239+
+
240+
.Properties of index template definition objects
241+
[%collapsible%open]
242+
243+
====
244+
245+
include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=request-body]
246+
247+
====
248+
228249
[[simulate-ingest-api-example]]
229250
==== {api-examples-title}
230251

0 commit comments

Comments
 (0)