1
0

simulate-pipeline.asciidoc 8.9 KB

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