simulate-pipeline.asciidoc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. [[simulate-pipeline-api]]
  2. === Simulate pipeline API
  3. ++++
  4. <titleabbrev>Simulate pipeline</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 an ingest pipeline against
  12. a set of provided documents.
  13. ////
  14. [source,console]
  15. ----
  16. PUT /_ingest/pipeline/my-pipeline-id
  17. {
  18. "description" : "example pipeline to simulate",
  19. "processors": [
  20. {
  21. "set" : {
  22. "field" : "field2",
  23. "value" : "_value"
  24. }
  25. }
  26. ]
  27. }
  28. ----
  29. // TESTSETUP
  30. ////
  31. [source,console]
  32. ----
  33. POST /_ingest/pipeline/my-pipeline-id/_simulate
  34. {
  35. "docs": [
  36. {
  37. "_index": "index",
  38. "_id": "id",
  39. "_source": {
  40. "foo": "bar"
  41. }
  42. },
  43. {
  44. "_index": "index",
  45. "_id": "id",
  46. "_source": {
  47. "foo": "rab"
  48. }
  49. }
  50. ]
  51. }
  52. ----
  53. [[simulate-pipeline-api-request]]
  54. ==== {api-request-title}
  55. `POST /_ingest/pipeline/<pipeline>/_simulate`
  56. `GET /_ingest/pipeline/<pipeline>/_simulate`
  57. `POST /_ingest/pipeline/_simulate`
  58. `GET /_ingest/pipeline/_simulate`
  59. [[simulate-pipeline-api-prereqs]]
  60. ==== {api-prereq-title}
  61. * If the {es} {security-features} are enabled, you must have the
  62. `read_pipeline`, `manage_pipeline`, `manage_ingest_pipelines`, or `manage`
  63. <<privileges-list-cluster,cluster privilege>> to use this API.
  64. [[simulate-pipeline-api-desc]]
  65. ==== {api-description-title}
  66. The simulate pipeline API executes a specific pipeline
  67. against a set of documents provided in the body of the request.
  68. You can either specify an existing pipeline
  69. to execute against the provided documents
  70. or supply a pipeline definition in the body of the request.
  71. [[simulate-pipeline-api-path-params]]
  72. ==== {api-path-parms-title}
  73. `<pipeline>`::
  74. (Required*, string)
  75. Pipeline to test. If you don't specify a `pipeline` in the request body, this
  76. parameter is required.
  77. [[simulate-pipeline-api-query-params]]
  78. ==== {api-query-parms-title}
  79. `verbose`::
  80. (Optional, Boolean)
  81. If `true`,
  82. the response includes output data
  83. for each processor in the executed pipeline.
  84. [role="child_attributes"]
  85. [[simulate-pipeline-api-request-body]]
  86. ==== {api-request-body-title}
  87. `pipeline`::
  88. (Required*, object)
  89. Pipeline to test. If you don't specify the `<pipeline>` request path parameter,
  90. this parameter is required. If you specify both this and the request path
  91. parameter, the API only uses the request path parameter.
  92. +
  93. .Properties of `pipeline`
  94. [%collapsible%open]
  95. ====
  96. include::put-pipeline.asciidoc[tag=pipeline-object]
  97. ====
  98. `docs`::
  99. (Required, array of objects)
  100. Sample documents to test in the pipeline.
  101. +
  102. .Properties of `docs` objects
  103. [%collapsible%open]
  104. ====
  105. `_id`::
  106. (Optional, string)
  107. Unique identifier for the document. This ID must be unique within the `_index`.
  108. `_index`::
  109. (Optional, string)
  110. Name of the index containing the document.
  111. `_routing`::
  112. (Optional, string)
  113. Value used to send the document to a specific primary shard. See the
  114. <<mapping-routing-field,`_routing`>> field.
  115. `_source`::
  116. (Required, object)
  117. JSON body for the document.
  118. ====
  119. [[simulate-pipeline-api-example]]
  120. ==== {api-examples-title}
  121. [[simulate-pipeline-api-path-parm-ex]]
  122. ===== Specify a pipeline as a path parameter
  123. [source,console]
  124. ----
  125. POST /_ingest/pipeline/my-pipeline-id/_simulate
  126. {
  127. "docs": [
  128. {
  129. "_index": "index",
  130. "_id": "id",
  131. "_source": {
  132. "foo": "bar"
  133. }
  134. },
  135. {
  136. "_index": "index",
  137. "_id": "id",
  138. "_source": {
  139. "foo": "rab"
  140. }
  141. }
  142. ]
  143. }
  144. ----
  145. The API returns the following response:
  146. [source,console-result]
  147. ----
  148. {
  149. "docs": [
  150. {
  151. "doc": {
  152. "_id": "id",
  153. "_index": "index",
  154. "_version": "-3",
  155. "_source": {
  156. "field2": "_value",
  157. "foo": "bar"
  158. },
  159. "_ingest": {
  160. "timestamp": "2017-05-04T22:30:03.187Z"
  161. }
  162. }
  163. },
  164. {
  165. "doc": {
  166. "_id": "id",
  167. "_index": "index",
  168. "_version": "-3",
  169. "_source": {
  170. "field2": "_value",
  171. "foo": "rab"
  172. },
  173. "_ingest": {
  174. "timestamp": "2017-05-04T22:30:03.188Z"
  175. }
  176. }
  177. }
  178. ]
  179. }
  180. ----
  181. // TESTRESPONSE[s/"2017-05-04T22:30:03.187Z"/$body.docs.0.doc._ingest.timestamp/]
  182. // TESTRESPONSE[s/"2017-05-04T22:30:03.188Z"/$body.docs.1.doc._ingest.timestamp/]
  183. [[simulate-pipeline-api-request-body-ex]]
  184. ===== Specify a pipeline in the request body
  185. [source,console]
  186. ----
  187. POST /_ingest/pipeline/_simulate
  188. {
  189. "pipeline" :
  190. {
  191. "description": "_description",
  192. "processors": [
  193. {
  194. "set" : {
  195. "field" : "field2",
  196. "value" : "_value"
  197. }
  198. }
  199. ]
  200. },
  201. "docs": [
  202. {
  203. "_index": "index",
  204. "_id": "id",
  205. "_source": {
  206. "foo": "bar"
  207. }
  208. },
  209. {
  210. "_index": "index",
  211. "_id": "id",
  212. "_source": {
  213. "foo": "rab"
  214. }
  215. }
  216. ]
  217. }
  218. ----
  219. The API returns the following response:
  220. [source,console-result]
  221. ----
  222. {
  223. "docs": [
  224. {
  225. "doc": {
  226. "_id": "id",
  227. "_index": "index",
  228. "_version": "-3",
  229. "_source": {
  230. "field2": "_value",
  231. "foo": "bar"
  232. },
  233. "_ingest": {
  234. "timestamp": "2017-05-04T22:30:03.187Z"
  235. }
  236. }
  237. },
  238. {
  239. "doc": {
  240. "_id": "id",
  241. "_index": "index",
  242. "_version": "-3",
  243. "_source": {
  244. "field2": "_value",
  245. "foo": "rab"
  246. },
  247. "_ingest": {
  248. "timestamp": "2017-05-04T22:30:03.188Z"
  249. }
  250. }
  251. }
  252. ]
  253. }
  254. ----
  255. // TESTRESPONSE[s/"2017-05-04T22:30:03.187Z"/$body.docs.0.doc._ingest.timestamp/]
  256. // TESTRESPONSE[s/"2017-05-04T22:30:03.188Z"/$body.docs.1.doc._ingest.timestamp/]
  257. [[ingest-verbose-param]]
  258. ===== View verbose results
  259. You can use the simulate pipeline API
  260. to see how each processor affects the ingest document
  261. as it passes through the pipeline.
  262. To see the intermediate results
  263. of each processor in the simulate request,
  264. you can add the `verbose` parameter to the request.
  265. [source,console]
  266. ----
  267. POST /_ingest/pipeline/_simulate?verbose=true
  268. {
  269. "pipeline" :
  270. {
  271. "description": "_description",
  272. "processors": [
  273. {
  274. "set" : {
  275. "field" : "field2",
  276. "value" : "_value2"
  277. }
  278. },
  279. {
  280. "set" : {
  281. "field" : "field3",
  282. "value" : "_value3"
  283. }
  284. }
  285. ]
  286. },
  287. "docs": [
  288. {
  289. "_index": "index",
  290. "_id": "id",
  291. "_source": {
  292. "foo": "bar"
  293. }
  294. },
  295. {
  296. "_index": "index",
  297. "_id": "id",
  298. "_source": {
  299. "foo": "rab"
  300. }
  301. }
  302. ]
  303. }
  304. ----
  305. The API returns the following response:
  306. [source,console-result]
  307. ----
  308. {
  309. "docs" : [
  310. {
  311. "processor_results" : [
  312. {
  313. "processor_type" : "set",
  314. "status" : "success",
  315. "doc" : {
  316. "_index" : "index",
  317. "_id" : "id",
  318. "_version": "-3",
  319. "_source" : {
  320. "field2" : "_value2",
  321. "foo" : "bar"
  322. },
  323. "_ingest" : {
  324. "pipeline" : "_simulate_pipeline",
  325. "timestamp" : "2020-07-30T01:21:24.251836Z"
  326. }
  327. }
  328. },
  329. {
  330. "processor_type" : "set",
  331. "status" : "success",
  332. "doc" : {
  333. "_index" : "index",
  334. "_id" : "id",
  335. "_version": "-3",
  336. "_source" : {
  337. "field3" : "_value3",
  338. "field2" : "_value2",
  339. "foo" : "bar"
  340. },
  341. "_ingest" : {
  342. "pipeline" : "_simulate_pipeline",
  343. "timestamp" : "2020-07-30T01:21:24.251836Z"
  344. }
  345. }
  346. }
  347. ]
  348. },
  349. {
  350. "processor_results" : [
  351. {
  352. "processor_type" : "set",
  353. "status" : "success",
  354. "doc" : {
  355. "_index" : "index",
  356. "_id" : "id",
  357. "_version": "-3",
  358. "_source" : {
  359. "field2" : "_value2",
  360. "foo" : "rab"
  361. },
  362. "_ingest" : {
  363. "pipeline" : "_simulate_pipeline",
  364. "timestamp" : "2020-07-30T01:21:24.251863Z"
  365. }
  366. }
  367. },
  368. {
  369. "processor_type" : "set",
  370. "status" : "success",
  371. "doc" : {
  372. "_index" : "index",
  373. "_id" : "id",
  374. "_version": "-3",
  375. "_source" : {
  376. "field3" : "_value3",
  377. "field2" : "_value2",
  378. "foo" : "rab"
  379. },
  380. "_ingest" : {
  381. "pipeline" : "_simulate_pipeline",
  382. "timestamp" : "2020-07-30T01:21:24.251863Z"
  383. }
  384. }
  385. }
  386. ]
  387. }
  388. ]
  389. }
  390. ----
  391. // TESTRESPONSE[s/"2020-07-30T01:21:24.251836Z"/$body.docs.0.processor_results.0.doc._ingest.timestamp/]
  392. // TESTRESPONSE[s/"2020-07-30T01:21:24.251836Z"/$body.docs.0.processor_results.1.doc._ingest.timestamp/]
  393. // TESTRESPONSE[s/"2020-07-30T01:21:24.251863Z"/$body.docs.1.processor_results.0.doc._ingest.timestamp/]
  394. // TESTRESPONSE[s/"2020-07-30T01:21:24.251863Z"/$body.docs.1.processor_results.1.doc._ingest.timestamp/]
  395. ////
  396. [source,console]
  397. ----
  398. DELETE /_ingest/pipeline/*
  399. ----
  400. [source,console-result]
  401. ----
  402. {
  403. "acknowledged": true
  404. }
  405. ----
  406. ////