simulate-pipeline.asciidoc 8.7 KB

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