Skip to content

Commit 7870e2d

Browse files
authored
Adding component template substitutions to the simulate ingest API (elastic#113276) (elastic#113567)
1 parent d06f7f2 commit 7870e2d

File tree

6 files changed

+434
-4
lines changed

6 files changed

+434
-4
lines changed

docs/changelog/113276.yaml

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
128128
[[put-component-template-api-request-body]]
129129
==== {api-request-body-title}
130130

131+
// tag::template[]
132+
131133
`template`::
132134
(Required, object)
133135
This is the template to be applied, may optionally include a `mappings`,
134136
`settings`, or `aliases` configuration.
135137
+
136138
.Properties of `template`
137139
[%collapsible%open]
138-
====
140+
=====
139141
`aliases`::
140142
(Optional, object of objects) Aliases to add.
141143
+
@@ -146,7 +148,7 @@ include::{es-ref-dir}/indices/create-index.asciidoc[tag=aliases-props]
146148
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=mappings]
147149
148150
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=settings]
149-
====
151+
=====
150152

151153
`version`::
152154
(Optional, integer)
@@ -173,6 +175,7 @@ This map is not automatically generated by {es}.
173175
Marks this component template as deprecated.
174176
When a deprecated component template is referenced when creating or updating a non-deprecated index template,
175177
{es} will emit a deprecation warning.
178+
end::template[]
176179

177180
[[put-component-template-api-example]]
178181
==== {api-examples-title}

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

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,32 @@ POST /_ingest/_simulate
8383
}
8484
]
8585
}
86+
},
87+
"component_template_substitutions": { <2>
88+
"my-component-template": {
89+
"template": {
90+
"mappings": {
91+
"dynamic": "true",
92+
"properties": {
93+
"field3": {
94+
"type": "keyword"
95+
}
96+
}
97+
},
98+
"settings": {
99+
"index": {
100+
"default_pipeline": "my-pipeline"
101+
}
102+
}
103+
}
104+
}
86105
}
87106
}
88107
----
89108

90109
<1> This replaces the existing `my-pipeline` pipeline with the contents given here for the duration of this request.
110+
<2> This replaces the existing `my-component-template` component template with the contents given here for the duration of this request.
111+
These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
91112

92113
[[simulate-ingest-api-request]]
93114
==== {api-request-title}
@@ -191,6 +212,19 @@ Map of pipeline IDs to substitute pipeline definition objects.
191212
include::put-pipeline.asciidoc[tag=pipeline-object]
192213
====
193214

215+
`component_template_substitutions`::
216+
(Optional, map of strings to objects)
217+
Map of component template names to substitute component template definition objects.
218+
+
219+
.Properties of component template definition objects
220+
[%collapsible%open]
221+
222+
====
223+
224+
include::{es-ref-dir}/indices/put-component-template.asciidoc[tag=template]
225+
226+
====
227+
194228
[[simulate-ingest-api-example]]
195229
==== {api-examples-title}
196230

@@ -268,7 +302,7 @@ The API returns the following response:
268302

269303
[[simulate-ingest-api-request-body-ex]]
270304
===== Specify a pipeline substitution in the request body
271-
In this example the index `index` has a default pipeline called `my-pipeline` and a final
305+
In this example the index `my-index` has a default pipeline called `my-pipeline` and a final
272306
pipeline called `my-final-pipeline`. But a substitute definition of `my-pipeline` is
273307
provided in `pipeline_substitutions`. The substitute `my-pipeline` will be used in place of
274308
the `my-pipeline` that is in the system, and then the `my-final-pipeline` that is already
@@ -348,6 +382,87 @@ The API returns the following response:
348382
}
349383
----
350384

385+
[[simulate-ingest-api-substitute-component-templates-ex]]
386+
===== Specify a component template substitution in the request body
387+
In this example, imagine that the index `my-index` has a strict mapping with only the `foo`
388+
keyword field defined. Say that field mapping came from a component template named
389+
`my-mappings-template`. We want to test adding a new field, `bar`. So a substitute definition of
390+
`my-mappings-template` is provided in `component_template_substitutions`. The substitute
391+
`my-mappings-template` will be used in place of the existing mapping for `my-index` and in place
392+
of the `my-mappings-template` that is in the system.
393+
394+
[source,console]
395+
----
396+
POST /_ingest/_simulate
397+
{
398+
"docs": [
399+
{
400+
"_index": "my-index",
401+
"_id": "123",
402+
"_source": {
403+
"foo": "foo"
404+
}
405+
},
406+
{
407+
"_index": "my-index",
408+
"_id": "456",
409+
"_source": {
410+
"bar": "rab"
411+
}
412+
}
413+
],
414+
"component_template_substitutions": {
415+
"my-mappings_template": {
416+
"template": {
417+
"mappings": {
418+
"dynamic": "strict",
419+
"properties": {
420+
"foo": {
421+
"type": "keyword"
422+
},
423+
"bar": {
424+
"type": "keyword"
425+
}
426+
}
427+
}
428+
}
429+
}
430+
}
431+
}
432+
----
433+
434+
The API returns the following response:
435+
436+
[source,console-result]
437+
----
438+
{
439+
"docs": [
440+
{
441+
"doc": {
442+
"_id": "123",
443+
"_index": "my-index",
444+
"_version": -3,
445+
"_source": {
446+
"foo": "foo"
447+
},
448+
"executed_pipelines": []
449+
}
450+
},
451+
{
452+
"doc": {
453+
"_id": "456",
454+
"_index": "my-index",
455+
"_version": -3,
456+
"_source": {
457+
"bar": "rab"
458+
},
459+
"executed_pipelines": []
460+
}
461+
}
462+
]
463+
}
464+
----
465+
351466
////
352467
[source,console]
353468
----

0 commit comments

Comments
 (0)