simulate-pipeline.asciidoc 8.4 KB

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