simulate-ingest.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. [[simulate-ingest-api]]
  2. === Simulate ingest API
  3. ++++
  4. <titleabbrev>Simulate ingest</titleabbrev>
  5. ++++
  6. .New API reference
  7. [sidebar]
  8. --
  9. For the most up-to-date API details, refer to {api-es}/group/endpoint-ingest[Ingest APIs].
  10. --
  11. Executes ingest pipelines against a set of provided documents, optionally
  12. with substitute pipeline definitions. This API is meant to be used for
  13. troubleshooting or pipeline development, as it does not actually index any
  14. data into {es}.
  15. ////
  16. [source,console]
  17. ----
  18. PUT /_ingest/pipeline/my-pipeline
  19. {
  20. "description" : "example pipeline to simulate",
  21. "processors": [
  22. {
  23. "set" : {
  24. "field" : "field1",
  25. "value" : "value1"
  26. }
  27. }
  28. ]
  29. }
  30. PUT /_ingest/pipeline/my-final-pipeline
  31. {
  32. "description" : "example final pipeline to simulate",
  33. "processors": [
  34. {
  35. "set" : {
  36. "field" : "field2",
  37. "value" : "value2"
  38. }
  39. }
  40. ]
  41. }
  42. PUT /my-index
  43. {
  44. "settings": {
  45. "index": {
  46. "default_pipeline": "my-pipeline",
  47. "final_pipeline": "my-final-pipeline"
  48. }
  49. }
  50. }
  51. ----
  52. // TESTSETUP
  53. ////
  54. [source,console]
  55. ----
  56. POST /_ingest/_simulate
  57. {
  58. "docs": [
  59. {
  60. "_index": "my-index",
  61. "_id": "id",
  62. "_source": {
  63. "foo": "bar"
  64. }
  65. },
  66. {
  67. "_index": "my-index",
  68. "_id": "id",
  69. "_source": {
  70. "foo": "rab"
  71. }
  72. }
  73. ],
  74. "pipeline_substitutions": { <1>
  75. "my-pipeline": {
  76. "processors": [
  77. {
  78. "set": {
  79. "field": "field3",
  80. "value": "value3"
  81. }
  82. }
  83. ]
  84. }
  85. },
  86. "component_template_substitutions": { <2>
  87. "my-component-template": {
  88. "template": {
  89. "mappings": {
  90. "dynamic": "true",
  91. "properties": {
  92. "field3": {
  93. "type": "keyword"
  94. }
  95. }
  96. },
  97. "settings": {
  98. "index": {
  99. "default_pipeline": "my-pipeline"
  100. }
  101. }
  102. }
  103. }
  104. },
  105. "index_template_substitutions": { <3>
  106. "my-index-template": {
  107. "index_patterns": ["my-index-*"],
  108. "composed_of": ["component_template_1", "component_template_2"]
  109. }
  110. },
  111. "mapping_addition": { <4>
  112. "dynamic": "strict",
  113. "properties": {
  114. "foo": {
  115. "type": "keyword"
  116. }
  117. }
  118. }
  119. }
  120. ----
  121. <1> This replaces the existing `my-pipeline` pipeline with the contents given here for the duration of this request.
  122. <2> This replaces the existing `my-component-template` component template with the contents given here for the duration of this request.
  123. These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
  124. <3> This replaces the existing `my-index-template` index template with the contents given here for the duration of this request.
  125. These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
  126. <4> This mapping is merged into the index's final mapping just before validation. It is used only for the duration of this request.
  127. [[simulate-ingest-api-request]]
  128. ==== {api-request-title}
  129. `POST /_ingest/_simulate`
  130. `GET /_ingest/_simulate`
  131. `POST /_ingest/<target>/_simulate`
  132. `GET /_ingest/<target>/_simulate`
  133. [[simulate-ingest-api-prereqs]]
  134. ==== {api-prereq-title}
  135. * If the {es} {security-features} are enabled, you must have the
  136. `index` or `create` <<privileges-list-indices,index privileges>>
  137. to use this API.
  138. [[simulate-ingest-api-desc]]
  139. ==== {api-description-title}
  140. The simulate ingest API simulates ingesting data into an index. It
  141. executes the default and final pipeline for that index against a set
  142. of documents provided in the body of the request. If a pipeline
  143. contains a <<reroute-processor,reroute processor>>, it follows that
  144. reroute processor to the new index, executing that index's pipelines
  145. as well the same way that a non-simulated ingest would. No data is
  146. indexed into {es}. Instead, the transformed document is returned,
  147. along with the list of pipelines that have been executed and the name
  148. of the index where the document would have been indexed if this were
  149. not a simulation. The transformed document is validated against the
  150. mappings that would apply to this index, and any validation error is
  151. reported in the result.
  152. This API differs from the
  153. <<simulate-pipeline-api,simulate pipeline API>> in that you specify a
  154. single pipeline for that API, and it only runs that one pipeline. The
  155. simulate pipeline API is more useful for developing a single pipeline,
  156. while the simulate ingest API is more useful for troubleshooting the
  157. interaction of the various pipelines that get applied when ingesting
  158. into an index.
  159. By default, the pipeline definitions that are currently in the system
  160. are used. However, you can supply substitute pipeline definitions in the
  161. body of the request. These will be used in place of the pipeline
  162. definitions that are already in the system. This can be used to replace
  163. existing pipeline definitions or to create new ones. The pipeline
  164. substitutions are only used within this request.
  165. [[simulate-ingest-api-path-params]]
  166. ==== {api-path-parms-title}
  167. `<target>`::
  168. (Optional, string)
  169. The index to simulate ingesting into. This can be overridden by specifying an index
  170. on each document. If you provide a <target> in the request path, it is used for any
  171. documents that don’t explicitly specify an index argument.
  172. [[simulate-ingest-api-query-params]]
  173. ==== {api-query-parms-title}
  174. `pipeline`::
  175. (Optional, string)
  176. Pipeline to use as the default pipeline. This can be used to override the default pipeline
  177. of the index being ingested into.
  178. [role="child_attributes"]
  179. [[simulate-ingest-api-request-body]]
  180. ==== {api-request-body-title}
  181. `docs`::
  182. (Required, array of objects)
  183. Sample documents to test in the pipeline.
  184. +
  185. .Properties of `docs` objects
  186. [%collapsible%open]
  187. ====
  188. `_id`::
  189. (Optional, string)
  190. Unique identifier for the document.
  191. `_index`::
  192. (Optional, string)
  193. Name of the index that the document will be ingested into.
  194. `_source`::
  195. (Required, object)
  196. JSON body for the document.
  197. ====
  198. `pipeline_substitutions`::
  199. (Optional, map of strings to objects)
  200. Map of pipeline IDs to substitute pipeline definition objects.
  201. +
  202. .Properties of pipeline definition objects
  203. [%collapsible%open]
  204. ====
  205. include::put-pipeline.asciidoc[tag=pipeline-object]
  206. ====
  207. `component_template_substitutions`::
  208. (Optional, map of strings to objects)
  209. Map of component template names to substitute component template definition objects.
  210. +
  211. .Properties of component template definition objects
  212. [%collapsible%open]
  213. ====
  214. include::{es-ref-dir}/indices/put-component-template.asciidoc[tag=template]
  215. ====
  216. `index_template_substitutions`::
  217. (Optional, map of strings to objects)
  218. Map of index template names to substitute index template definition objects.
  219. +
  220. .Properties of index template definition objects
  221. [%collapsible%open]
  222. ====
  223. include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=request-body]
  224. ====
  225. `mapping_addition`::
  226. (Optional, <<mapping,mapping object>>)
  227. Definition of a mapping that will be merged into the index's mapping for validation during the course of this request.
  228. [[simulate-ingest-api-example]]
  229. ==== {api-examples-title}
  230. [[simulate-ingest-api-pre-existing-pipelines-ex]]
  231. ===== Use pre-existing pipeline definitions
  232. In this example the index `index` has a default pipeline called `my-pipeline` and a final
  233. pipeline called `my-final-pipeline`. Since both documents are being ingested into `index`,
  234. both pipelines are executed using the pipeline definitions that are already in the system.
  235. [source,console]
  236. ----
  237. POST /_ingest/_simulate
  238. {
  239. "docs": [
  240. {
  241. "_index": "my-index",
  242. "_id": "123",
  243. "_source": {
  244. "foo": "bar"
  245. }
  246. },
  247. {
  248. "_index": "my-index",
  249. "_id": "456",
  250. "_source": {
  251. "foo": "rab"
  252. }
  253. }
  254. ]
  255. }
  256. ----
  257. The API returns the following response:
  258. [source,console-result]
  259. ----
  260. {
  261. "docs": [
  262. {
  263. "doc": {
  264. "_id": "123",
  265. "_index": "my-index",
  266. "_version": -3,
  267. "_source": {
  268. "field1": "value1",
  269. "field2": "value2",
  270. "foo": "bar"
  271. },
  272. "executed_pipelines": [
  273. "my-pipeline",
  274. "my-final-pipeline"
  275. ]
  276. }
  277. },
  278. {
  279. "doc": {
  280. "_id": "456",
  281. "_index": "my-index",
  282. "_version": -3,
  283. "_source": {
  284. "field1": "value1",
  285. "field2": "value2",
  286. "foo": "rab"
  287. },
  288. "executed_pipelines": [
  289. "my-pipeline",
  290. "my-final-pipeline"
  291. ]
  292. }
  293. }
  294. ]
  295. }
  296. ----
  297. [[simulate-ingest-api-request-body-ex]]
  298. ===== Specify a pipeline substitution in the request body
  299. In this example the index `my-index` has a default pipeline called `my-pipeline` and a final
  300. pipeline called `my-final-pipeline`. But a substitute definition of `my-pipeline` is
  301. provided in `pipeline_substitutions`. The substitute `my-pipeline` will be used in place of
  302. the `my-pipeline` that is in the system, and then the `my-final-pipeline` that is already
  303. defined in the system will be executed.
  304. [source,console]
  305. ----
  306. POST /_ingest/_simulate
  307. {
  308. "docs": [
  309. {
  310. "_index": "my-index",
  311. "_id": "123",
  312. "_source": {
  313. "foo": "bar"
  314. }
  315. },
  316. {
  317. "_index": "my-index",
  318. "_id": "456",
  319. "_source": {
  320. "foo": "rab"
  321. }
  322. }
  323. ],
  324. "pipeline_substitutions": {
  325. "my-pipeline": {
  326. "processors": [
  327. {
  328. "uppercase": {
  329. "field": "foo"
  330. }
  331. }
  332. ]
  333. }
  334. }
  335. }
  336. ----
  337. The API returns the following response:
  338. [source,console-result]
  339. ----
  340. {
  341. "docs": [
  342. {
  343. "doc": {
  344. "_id": "123",
  345. "_index": "my-index",
  346. "_version": -3,
  347. "_source": {
  348. "field2": "value2",
  349. "foo": "BAR"
  350. },
  351. "executed_pipelines": [
  352. "my-pipeline",
  353. "my-final-pipeline"
  354. ]
  355. }
  356. },
  357. {
  358. "doc": {
  359. "_id": "456",
  360. "_index": "my-index",
  361. "_version": -3,
  362. "_source": {
  363. "field2": "value2",
  364. "foo": "RAB"
  365. },
  366. "executed_pipelines": [
  367. "my-pipeline",
  368. "my-final-pipeline"
  369. ]
  370. }
  371. }
  372. ]
  373. }
  374. ----
  375. [[simulate-ingest-api-substitute-component-templates-ex]]
  376. ===== Specify a component template substitution in the request body
  377. In this example, imagine that the index `my-index` has a strict mapping with only the `foo`
  378. keyword field defined. Say that field mapping came from a component template named
  379. `my-mappings-template`. We want to test adding a new field, `bar`. So a substitute definition of
  380. `my-mappings-template` is provided in `component_template_substitutions`. The substitute
  381. `my-mappings-template` will be used in place of the existing mapping for `my-index` and in place
  382. of the `my-mappings-template` that is in the system.
  383. [source,console]
  384. ----
  385. POST /_ingest/_simulate
  386. {
  387. "docs": [
  388. {
  389. "_index": "my-index",
  390. "_id": "123",
  391. "_source": {
  392. "foo": "foo"
  393. }
  394. },
  395. {
  396. "_index": "my-index",
  397. "_id": "456",
  398. "_source": {
  399. "bar": "rab"
  400. }
  401. }
  402. ],
  403. "component_template_substitutions": {
  404. "my-mappings_template": {
  405. "template": {
  406. "mappings": {
  407. "dynamic": "strict",
  408. "properties": {
  409. "foo": {
  410. "type": "keyword"
  411. },
  412. "bar": {
  413. "type": "keyword"
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. ----
  422. The API returns the following response:
  423. [source,console-result]
  424. ----
  425. {
  426. "docs": [
  427. {
  428. "doc": {
  429. "_id": "123",
  430. "_index": "my-index",
  431. "_version": -3,
  432. "_source": {
  433. "foo": "foo"
  434. },
  435. "executed_pipelines": []
  436. }
  437. },
  438. {
  439. "doc": {
  440. "_id": "456",
  441. "_index": "my-index",
  442. "_version": -3,
  443. "_source": {
  444. "bar": "rab"
  445. },
  446. "executed_pipelines": []
  447. }
  448. }
  449. ]
  450. }
  451. ----
  452. ////
  453. [source,console]
  454. ----
  455. DELETE /my-index
  456. DELETE /_ingest/pipeline/*
  457. ----
  458. [source,console-result]
  459. ----
  460. {
  461. "acknowledged": true
  462. }
  463. ----
  464. ////