ingest-node.asciidoc 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. [[pipeline]]
  2. == Pipeline Definition
  3. A pipeline is a definition of a series of <<ingest-processors, processors>> that are to be executed
  4. in the same order as they are declared. A pipeline consists of two main fields: a `description`
  5. and a list of `processors`:
  6. [source,js]
  7. --------------------------------------------------
  8. {
  9. "description" : "...",
  10. "processors" : [ ... ]
  11. }
  12. --------------------------------------------------
  13. // NOTCONSOLE
  14. The `description` is a special field to store a helpful description of
  15. what the pipeline does.
  16. The `processors` parameter defines a list of processors to be executed in
  17. order.
  18. [[ingest-apis]]
  19. == Ingest APIs
  20. The following ingest APIs are available for managing pipelines:
  21. * <<put-pipeline-api>> to add or update a pipeline
  22. * <<get-pipeline-api>> to return a specific pipeline
  23. * <<delete-pipeline-api>> to delete a pipeline
  24. * <<simulate-pipeline-api>> to simulate a call to a pipeline
  25. [[put-pipeline-api]]
  26. === Put Pipeline API
  27. The put pipeline API adds pipelines and updates existing pipelines in the cluster.
  28. [source,js]
  29. --------------------------------------------------
  30. PUT _ingest/pipeline/my-pipeline-id
  31. {
  32. "description" : "describe pipeline",
  33. "processors" : [
  34. {
  35. "set" : {
  36. "field": "foo",
  37. "value": "bar"
  38. }
  39. }
  40. ]
  41. }
  42. --------------------------------------------------
  43. // CONSOLE
  44. NOTE: The put pipeline API also instructs all ingest nodes to reload their in-memory representation of pipelines, so that
  45. pipeline changes take effect immediately.
  46. [[get-pipeline-api]]
  47. === Get Pipeline API
  48. The get pipeline API returns pipelines based on ID. This API always returns a local reference of the pipeline.
  49. [source,js]
  50. --------------------------------------------------
  51. GET _ingest/pipeline/my-pipeline-id
  52. --------------------------------------------------
  53. // CONSOLE
  54. // TEST[continued]
  55. Example response:
  56. [source,js]
  57. --------------------------------------------------
  58. {
  59. "my-pipeline-id" : {
  60. "description" : "describe pipeline",
  61. "processors" : [
  62. {
  63. "set" : {
  64. "field" : "foo",
  65. "value" : "bar"
  66. }
  67. }
  68. ]
  69. }
  70. }
  71. --------------------------------------------------
  72. // TESTRESPONSE
  73. For each returned pipeline, the source and the version are returned.
  74. The version is useful for knowing which version of the pipeline the node has.
  75. You can specify multiple IDs to return more than one pipeline. Wildcards are also supported.
  76. [float]
  77. [[versioning-pipelines]]
  78. ==== Pipeline Versioning
  79. Pipelines can optionally add a `version` number, which can be any integer value,
  80. in order to simplify pipeline management by external systems. The `version`
  81. field is completely optional and it is meant solely for external management of
  82. pipelines. To unset a `version`, simply replace the pipeline without specifying
  83. one.
  84. [source,js]
  85. --------------------------------------------------
  86. PUT _ingest/pipeline/my-pipeline-id
  87. {
  88. "description" : "describe pipeline",
  89. "version" : 123,
  90. "processors" : [
  91. {
  92. "set" : {
  93. "field": "foo",
  94. "value": "bar"
  95. }
  96. }
  97. ]
  98. }
  99. --------------------------------------------------
  100. // CONSOLE
  101. To check for the `version`, you can
  102. <<common-options-response-filtering, filter responses>>
  103. using `filter_path` to limit the response to just the `version`:
  104. [source,js]
  105. --------------------------------------------------
  106. GET /_ingest/pipeline/my-pipeline-id?filter_path=*.version
  107. --------------------------------------------------
  108. // CONSOLE
  109. // TEST[continued]
  110. This should give a small response that makes it both easy and inexpensive to parse:
  111. [source,js]
  112. --------------------------------------------------
  113. {
  114. "my-pipeline-id" : {
  115. "version" : 123
  116. }
  117. }
  118. --------------------------------------------------
  119. // TESTRESPONSE
  120. [[delete-pipeline-api]]
  121. === Delete Pipeline API
  122. The delete pipeline API deletes pipelines by ID or wildcard match (`my-*`, `*`).
  123. [source,js]
  124. --------------------------------------------------
  125. DELETE _ingest/pipeline/my-pipeline-id
  126. --------------------------------------------------
  127. // CONSOLE
  128. // TEST[continued]
  129. ////
  130. Hidden setup for wildcard test:
  131. [source,js]
  132. --------------------------------------------------
  133. PUT _ingest/pipeline/wild-one
  134. {
  135. "description" : "first pipeline to be wildcard deleted",
  136. "processors" : [ ]
  137. }
  138. PUT _ingest/pipeline/wild-two
  139. {
  140. "description" : "second pipeline to be wildcard deleted",
  141. "processors" : [ ]
  142. }
  143. DELETE _ingest/pipeline/*
  144. --------------------------------------------------
  145. // CONSOLE
  146. Hidden expected response:
  147. [source,js]
  148. --------------------------------------------------
  149. {
  150. "acknowledged": true
  151. }
  152. --------------------------------------------------
  153. // TESTRESPONSE
  154. ////
  155. [[simulate-pipeline-api]]
  156. === Simulate Pipeline API
  157. The simulate pipeline API executes a specific pipeline against
  158. the set of documents provided in the body of the request.
  159. You can either specify an existing pipeline to execute
  160. against the provided documents, or supply a pipeline definition in
  161. the body of the request.
  162. Here is the structure of a simulate request with a pipeline definition provided
  163. in the body of the request:
  164. [source,js]
  165. --------------------------------------------------
  166. POST _ingest/pipeline/_simulate
  167. {
  168. "pipeline" : {
  169. // pipeline definition here
  170. },
  171. "docs" : [
  172. { "_source": {/** first document **/} },
  173. { "_source": {/** second document **/} },
  174. // ...
  175. ]
  176. }
  177. --------------------------------------------------
  178. // NOTCONSOLE
  179. Here is the structure of a simulate request against an existing pipeline:
  180. [source,js]
  181. --------------------------------------------------
  182. POST _ingest/pipeline/my-pipeline-id/_simulate
  183. {
  184. "docs" : [
  185. { "_source": {/** first document **/} },
  186. { "_source": {/** second document **/} },
  187. // ...
  188. ]
  189. }
  190. --------------------------------------------------
  191. // NOTCONSOLE
  192. Here is an example of a simulate request with a pipeline defined in the request
  193. and its response:
  194. [source,js]
  195. --------------------------------------------------
  196. POST _ingest/pipeline/_simulate
  197. {
  198. "pipeline" :
  199. {
  200. "description": "_description",
  201. "processors": [
  202. {
  203. "set" : {
  204. "field" : "field2",
  205. "value" : "_value"
  206. }
  207. }
  208. ]
  209. },
  210. "docs": [
  211. {
  212. "_index": "index",
  213. "_type": "type",
  214. "_id": "id",
  215. "_source": {
  216. "foo": "bar"
  217. }
  218. },
  219. {
  220. "_index": "index",
  221. "_type": "type",
  222. "_id": "id",
  223. "_source": {
  224. "foo": "rab"
  225. }
  226. }
  227. ]
  228. }
  229. --------------------------------------------------
  230. // CONSOLE
  231. Response:
  232. [source,js]
  233. --------------------------------------------------
  234. {
  235. "docs": [
  236. {
  237. "doc": {
  238. "_id": "id",
  239. "_index": "index",
  240. "_type": "type",
  241. "_source": {
  242. "field2": "_value",
  243. "foo": "bar"
  244. },
  245. "_ingest": {
  246. "timestamp": "2017-05-04T22:30:03.187Z"
  247. }
  248. }
  249. },
  250. {
  251. "doc": {
  252. "_id": "id",
  253. "_index": "index",
  254. "_type": "type",
  255. "_source": {
  256. "field2": "_value",
  257. "foo": "rab"
  258. },
  259. "_ingest": {
  260. "timestamp": "2017-05-04T22:30:03.188Z"
  261. }
  262. }
  263. }
  264. ]
  265. }
  266. --------------------------------------------------
  267. // TESTRESPONSE[s/"2017-05-04T22:30:03.187Z"/$body.docs.0.doc._ingest.timestamp/]
  268. // TESTRESPONSE[s/"2017-05-04T22:30:03.188Z"/$body.docs.1.doc._ingest.timestamp/]
  269. [[ingest-verbose-param]]
  270. ==== Viewing Verbose Results
  271. You can use the simulate pipeline API to see how each processor affects the ingest document
  272. as it passes through the pipeline. To see the intermediate results of
  273. each processor in the simulate request, you can add the `verbose` parameter
  274. to the request.
  275. Here is an example of a verbose request and its response:
  276. [source,js]
  277. --------------------------------------------------
  278. POST _ingest/pipeline/_simulate?verbose
  279. {
  280. "pipeline" :
  281. {
  282. "description": "_description",
  283. "processors": [
  284. {
  285. "set" : {
  286. "field" : "field2",
  287. "value" : "_value2"
  288. }
  289. },
  290. {
  291. "set" : {
  292. "field" : "field3",
  293. "value" : "_value3"
  294. }
  295. }
  296. ]
  297. },
  298. "docs": [
  299. {
  300. "_index": "index",
  301. "_type": "type",
  302. "_id": "id",
  303. "_source": {
  304. "foo": "bar"
  305. }
  306. },
  307. {
  308. "_index": "index",
  309. "_type": "type",
  310. "_id": "id",
  311. "_source": {
  312. "foo": "rab"
  313. }
  314. }
  315. ]
  316. }
  317. --------------------------------------------------
  318. // CONSOLE
  319. Response:
  320. [source,js]
  321. --------------------------------------------------
  322. {
  323. "docs": [
  324. {
  325. "processor_results": [
  326. {
  327. "doc": {
  328. "_id": "id",
  329. "_index": "index",
  330. "_type": "type",
  331. "_source": {
  332. "field2": "_value2",
  333. "foo": "bar"
  334. },
  335. "_ingest": {
  336. "timestamp": "2017-05-04T22:46:09.674Z"
  337. }
  338. }
  339. },
  340. {
  341. "doc": {
  342. "_id": "id",
  343. "_index": "index",
  344. "_type": "type",
  345. "_source": {
  346. "field3": "_value3",
  347. "field2": "_value2",
  348. "foo": "bar"
  349. },
  350. "_ingest": {
  351. "timestamp": "2017-05-04T22:46:09.675Z"
  352. }
  353. }
  354. }
  355. ]
  356. },
  357. {
  358. "processor_results": [
  359. {
  360. "doc": {
  361. "_id": "id",
  362. "_index": "index",
  363. "_type": "type",
  364. "_source": {
  365. "field2": "_value2",
  366. "foo": "rab"
  367. },
  368. "_ingest": {
  369. "timestamp": "2017-05-04T22:46:09.676Z"
  370. }
  371. }
  372. },
  373. {
  374. "doc": {
  375. "_id": "id",
  376. "_index": "index",
  377. "_type": "type",
  378. "_source": {
  379. "field3": "_value3",
  380. "field2": "_value2",
  381. "foo": "rab"
  382. },
  383. "_ingest": {
  384. "timestamp": "2017-05-04T22:46:09.677Z"
  385. }
  386. }
  387. }
  388. ]
  389. }
  390. ]
  391. }
  392. --------------------------------------------------
  393. // TESTRESPONSE[s/"2017-05-04T22:46:09.674Z"/$body.docs.0.processor_results.0.doc._ingest.timestamp/]
  394. // TESTRESPONSE[s/"2017-05-04T22:46:09.675Z"/$body.docs.0.processor_results.1.doc._ingest.timestamp/]
  395. // TESTRESPONSE[s/"2017-05-04T22:46:09.676Z"/$body.docs.1.processor_results.0.doc._ingest.timestamp/]
  396. // TESTRESPONSE[s/"2017-05-04T22:46:09.677Z"/$body.docs.1.processor_results.1.doc._ingest.timestamp/]
  397. [[accessing-data-in-pipelines]]
  398. == Accessing Data in Pipelines
  399. The processors in a pipeline have read and write access to documents that pass through the pipeline.
  400. The processors can access fields in the source of a document and the document's metadata fields.
  401. [float]
  402. [[accessing-source-fields]]
  403. === Accessing Fields in the Source
  404. Accessing a field in the source is straightforward. You simply refer to fields by
  405. their name. For example:
  406. [source,js]
  407. --------------------------------------------------
  408. {
  409. "set": {
  410. "field": "my_field"
  411. "value": 582.1
  412. }
  413. }
  414. --------------------------------------------------
  415. // NOTCONSOLE
  416. On top of this, fields from the source are always accessible via the `_source` prefix:
  417. [source,js]
  418. --------------------------------------------------
  419. {
  420. "set": {
  421. "field": "_source.my_field"
  422. "value": 582.1
  423. }
  424. }
  425. --------------------------------------------------
  426. // NOTCONSOLE
  427. [float]
  428. [[accessing-metadata-fields]]
  429. === Accessing Metadata Fields
  430. You can access metadata fields in the same way that you access fields in the source. This
  431. is possible because Elasticsearch doesn't allow fields in the source that have the
  432. same name as metadata fields.
  433. The following example sets the `_id` metadata field of a document to `1`:
  434. [source,js]
  435. --------------------------------------------------
  436. {
  437. "set": {
  438. "field": "_id"
  439. "value": "1"
  440. }
  441. }
  442. --------------------------------------------------
  443. // NOTCONSOLE
  444. The following metadata fields are accessible by a processor: `_index`, `_type`, `_id`, `_routing`.
  445. [float]
  446. [[accessing-ingest-metadata]]
  447. === Accessing Ingest Metadata Fields
  448. Beyond metadata fields and source fields, ingest also adds ingest metadata to the documents that it processes.
  449. These metadata properties are accessible under the `_ingest` key. Currently ingest adds the ingest timestamp
  450. under the `_ingest.timestamp` key of the ingest metadata. The ingest timestamp is the time when Elasticsearch
  451. received the index or bulk request to pre-process the document.
  452. Any processor can add ingest-related metadata during document processing. Ingest metadata is transient
  453. and is lost after a document has been processed by the pipeline. Therefore, ingest metadata won't be indexed.
  454. The following example adds a field with the name `received`. The value is the ingest timestamp:
  455. [source,js]
  456. --------------------------------------------------
  457. {
  458. "set": {
  459. "field": "received"
  460. "value": "{{_ingest.timestamp}}"
  461. }
  462. }
  463. --------------------------------------------------
  464. // NOTCONSOLE
  465. Unlike Elasticsearch metadata fields, the ingest metadata field name `_ingest` can be used as a valid field name
  466. in the source of a document. Use `_source._ingest` to refer to the field in the source document. Otherwise, `_ingest`
  467. will be interpreted as an ingest metadata field.
  468. [float]
  469. [[accessing-template-fields]]
  470. === Accessing Fields and Metafields in Templates
  471. A number of processor settings also support templating. Settings that support templating can have zero or more
  472. template snippets. A template snippet begins with `{{` and ends with `}}`.
  473. Accessing fields and metafields in templates is exactly the same as via regular processor field settings.
  474. The following example adds a field named `field_c`. Its value is a concatenation of
  475. the values of `field_a` and `field_b`.
  476. [source,js]
  477. --------------------------------------------------
  478. {
  479. "set": {
  480. "field": "field_c"
  481. "value": "{{field_a}} {{field_b}}"
  482. }
  483. }
  484. --------------------------------------------------
  485. // NOTCONSOLE
  486. The following example uses the value of the `geoip.country_iso_code` field in the source
  487. to set the index that the document will be indexed into:
  488. [source,js]
  489. --------------------------------------------------
  490. {
  491. "set": {
  492. "field": "_index"
  493. "value": "{{geoip.country_iso_code}}"
  494. }
  495. }
  496. --------------------------------------------------
  497. // NOTCONSOLE
  498. [[handling-failure-in-pipelines]]
  499. == Handling Failures in Pipelines
  500. In its simplest use case, a pipeline defines a list of processors that
  501. are executed sequentially, and processing halts at the first exception. This
  502. behavior may not be desirable when failures are expected. For example, you may have logs
  503. that don't match the specified grok expression. Instead of halting execution, you may
  504. want to index such documents into a separate index.
  505. To enable this behavior, you can use the `on_failure` parameter. The `on_failure` parameter
  506. defines a list of processors to be executed immediately following the failed processor.
  507. You can specify this parameter at the pipeline level, as well as at the processor
  508. level. If a processor specifies an `on_failure` configuration, whether
  509. it is empty or not, any exceptions that are thrown by the processor are caught, and the
  510. pipeline continues executing the remaining processors. Because you can define further processors
  511. within the scope of an `on_failure` statement, you can nest failure handling.
  512. The following example defines a pipeline that renames the `foo` field in
  513. the processed document to `bar`. If the document does not contain the `foo` field, the processor
  514. attaches an error message to the document for later analysis within
  515. Elasticsearch.
  516. [source,js]
  517. --------------------------------------------------
  518. {
  519. "description" : "my first pipeline with handled exceptions",
  520. "processors" : [
  521. {
  522. "rename" : {
  523. "field" : "foo",
  524. "target_field" : "bar",
  525. "on_failure" : [
  526. {
  527. "set" : {
  528. "field" : "error",
  529. "value" : "field \"foo\" does not exist, cannot rename to \"bar\""
  530. }
  531. }
  532. ]
  533. }
  534. }
  535. ]
  536. }
  537. --------------------------------------------------
  538. // NOTCONSOLE
  539. The following example defines an `on_failure` block on a whole pipeline to change
  540. the index to which failed documents get sent.
  541. [source,js]
  542. --------------------------------------------------
  543. {
  544. "description" : "my first pipeline with handled exceptions",
  545. "processors" : [ ... ],
  546. "on_failure" : [
  547. {
  548. "set" : {
  549. "field" : "_index",
  550. "value" : "failed-{{ _index }}"
  551. }
  552. }
  553. ]
  554. }
  555. --------------------------------------------------
  556. // NOTCONSOLE
  557. Alternatively instead of defining behaviour in case of processor failure, it is also possible
  558. to ignore a failure and continue with the next processor by specifying the `ignore_failure` setting.
  559. In case in the example below the field `foo` doesn't exist the failure will be caught and the pipeline
  560. continues to execute, which in this case means that the pipeline does nothing.
  561. [source,js]
  562. --------------------------------------------------
  563. {
  564. "description" : "my first pipeline with handled exceptions",
  565. "processors" : [
  566. {
  567. "rename" : {
  568. "field" : "foo",
  569. "target_field" : "bar",
  570. "ignore_failure" : true
  571. }
  572. }
  573. ]
  574. }
  575. --------------------------------------------------
  576. // NOTCONSOLE
  577. The `ignore_failure` can be set on any processor and defaults to `false`.
  578. [float]
  579. [[accessing-error-metadata]]
  580. === Accessing Error Metadata From Processors Handling Exceptions
  581. You may want to retrieve the actual error message that was thrown
  582. by a failed processor. To do so you can access metadata fields called
  583. `on_failure_message`, `on_failure_processor_type`, and `on_failure_processor_tag`. These fields are only accessible
  584. from within the context of an `on_failure` block.
  585. Here is an updated version of the example that you
  586. saw earlier. But instead of setting the error message manually, the example leverages the `on_failure_message`
  587. metadata field to provide the error message.
  588. [source,js]
  589. --------------------------------------------------
  590. {
  591. "description" : "my first pipeline with handled exceptions",
  592. "processors" : [
  593. {
  594. "rename" : {
  595. "field" : "foo",
  596. "to" : "bar",
  597. "on_failure" : [
  598. {
  599. "set" : {
  600. "field" : "error",
  601. "value" : "{{ _ingest.on_failure_message }}"
  602. }
  603. }
  604. ]
  605. }
  606. }
  607. ]
  608. }
  609. --------------------------------------------------
  610. // NOTCONSOLE
  611. [[ingest-processors]]
  612. == Processors
  613. All processors are defined in the following way within a pipeline definition:
  614. [source,js]
  615. --------------------------------------------------
  616. {
  617. "PROCESSOR_NAME" : {
  618. ... processor configuration options ...
  619. }
  620. }
  621. --------------------------------------------------
  622. // NOTCONSOLE
  623. Each processor defines its own configuration parameters, but all processors have
  624. the ability to declare `tag` and `on_failure` fields. These fields are optional.
  625. A `tag` is simply a string identifier of the specific instantiation of a certain
  626. processor in a pipeline. The `tag` field does not affect the processor's behavior,
  627. but is very useful for bookkeeping and tracing errors to specific processors.
  628. See <<handling-failure-in-pipelines>> to learn more about the `on_failure` field and error handling in pipelines.
  629. The <<ingest-info,node info API>> can be used to figure out what processors are available in a cluster.
  630. The <<ingest-info,node info API>> will provide a per node list of what processors are available.
  631. Custom processors must be installed on all nodes. The put pipeline API will fail if a processor specified in a pipeline
  632. doesn't exist on all nodes. If you rely on custom processor plugins make sure to mark these plugins as mandatory by adding
  633. `plugin.mandatory` setting to the `config/elasticsearch.yml` file, for example:
  634. [source,yaml]
  635. --------------------------------------------------
  636. plugin.mandatory: ingest-attachment,ingest-geoip
  637. --------------------------------------------------
  638. A node will not start if either of these plugins are not available.
  639. The <<ingest-stats,node stats API>> can be used to fetch ingest usage statistics, globally and on a per
  640. pipeline basis. Useful to find out which pipelines are used the most or spent the most time on preprocessing.
  641. [[append-processor]]
  642. === Append Processor
  643. Appends one or more values to an existing array if the field already exists and it is an array.
  644. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar.
  645. Creates an array containing the provided values if the field doesn't exist.
  646. Accepts a single value or an array of values.
  647. [[append-options]]
  648. .Append Options
  649. [options="header"]
  650. |======
  651. | Name | Required | Default | Description
  652. | `field` | yes | - | The field to be appended to
  653. | `value` | yes | - | The value to be appended
  654. |======
  655. [source,js]
  656. --------------------------------------------------
  657. {
  658. "append": {
  659. "field": "field1",
  660. "value": ["item2", "item3", "item4"]
  661. }
  662. }
  663. --------------------------------------------------
  664. // NOTCONSOLE
  665. [[convert-processor]]
  666. === Convert Processor
  667. Converts an existing field's value to a different type, such as converting a string to an integer.
  668. If the field value is an array, all members will be converted.
  669. The supported types include: `integer`, `float`, `string`, `boolean`, and `auto`.
  670. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  671. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  672. Specifying `auto` will attempt to convert the string-valued `field` into the closest non-string type.
  673. For example, a field whose value is `"true"` will be converted to its respective boolean type: `true`. And
  674. a value of `"242.15"` will "automatically" be converted to `242.15` of type `float`. If a provided field cannot
  675. be appropriately converted, the Convert Processor will still process successfully and leave the field value as-is. In
  676. such a case, `target_field` will still be updated with the unconverted field value.
  677. [[convert-options]]
  678. .Convert Options
  679. [options="header"]
  680. |======
  681. | Name | Required | Default | Description
  682. | `field` | yes | - | The field whose value is to be converted
  683. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  684. | `type` | yes | - | The type to convert the existing value to
  685. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  686. |======
  687. [source,js]
  688. --------------------------------------------------
  689. {
  690. "convert": {
  691. "field" : "foo",
  692. "type": "integer"
  693. }
  694. }
  695. --------------------------------------------------
  696. // NOTCONSOLE
  697. [[date-processor]]
  698. === Date Processor
  699. Parses dates from fields, and then uses the date or timestamp as the timestamp for the document.
  700. By default, the date processor adds the parsed date as a new field called `@timestamp`. You can specify a
  701. different field by setting the `target_field` configuration parameter. Multiple date formats are supported
  702. as part of the same date processor definition. They will be used sequentially to attempt parsing the date field,
  703. in the same order they were defined as part of the processor definition.
  704. [[date-options]]
  705. .Date options
  706. [options="header"]
  707. |======
  708. | Name | Required | Default | Description
  709. | `field` | yes | - | The field to get the date from.
  710. | `target_field` | no | @timestamp | The field that will hold the parsed date.
  711. | `formats` | yes | - | An array of the expected date formats. Can be a Joda pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
  712. | `timezone` | no | UTC | The timezone to use when parsing the date.
  713. | `locale` | no | ENGLISH | The locale to use when parsing the date, relevant when parsing month names or week days.
  714. |======
  715. Here is an example that adds the parsed date to the `timestamp` field based on the `initial_date` field:
  716. [source,js]
  717. --------------------------------------------------
  718. {
  719. "description" : "...",
  720. "processors" : [
  721. {
  722. "date" : {
  723. "field" : "initial_date",
  724. "target_field" : "timestamp",
  725. "formats" : ["dd/MM/yyyy hh:mm:ss"],
  726. "timezone" : "Europe/Amsterdam"
  727. }
  728. }
  729. ]
  730. }
  731. --------------------------------------------------
  732. // NOTCONSOLE
  733. [[date-index-name-processor]]
  734. === Date Index Name Processor
  735. The purpose of this processor is to point documents to the right time based index based
  736. on a date or timestamp field in a document by using the <<date-math-index-names, date math index name support>>.
  737. The processor sets the `_index` meta field with a date math index name expression based on the provided index name
  738. prefix, a date or timestamp field in the documents being processed and the provided date rounding.
  739. First, this processor fetches the date or timestamp from a field in the document being processed. Optionally,
  740. date formatting can be configured on how the field's value should be parsed into a date. Then this date,
  741. the provided index name prefix and the provided date rounding get formatted into a date math index name expression.
  742. Also here optionally date formatting can be specified on how the date should be formatted into a date math index name
  743. expression.
  744. An example pipeline that points documents to a monthly index that starts with a `myindex-` prefix based on a
  745. date in the `date1` field:
  746. [source,js]
  747. --------------------------------------------------
  748. PUT _ingest/pipeline/monthlyindex
  749. {
  750. "description": "monthly date-time index naming",
  751. "processors" : [
  752. {
  753. "date_index_name" : {
  754. "field" : "date1",
  755. "index_name_prefix" : "myindex-",
  756. "date_rounding" : "M"
  757. }
  758. }
  759. ]
  760. }
  761. --------------------------------------------------
  762. // CONSOLE
  763. Using that pipeline for an index request:
  764. [source,js]
  765. --------------------------------------------------
  766. PUT /myindex/type/1?pipeline=monthlyindex
  767. {
  768. "date1" : "2016-04-25T12:02:01.789Z"
  769. }
  770. --------------------------------------------------
  771. // CONSOLE
  772. // TEST[continued]
  773. [source,js]
  774. --------------------------------------------------
  775. {
  776. "_index" : "myindex-2016-04-01",
  777. "_type" : "type",
  778. "_id" : "1",
  779. "_version" : 1,
  780. "result" : "created",
  781. "_shards" : {
  782. "total" : 2,
  783. "successful" : 1,
  784. "failed" : 0
  785. },
  786. "_seq_no" : 0,
  787. "_primary_term" : 1
  788. }
  789. --------------------------------------------------
  790. // TESTRESPONSE
  791. The above request will not index this document into the `myindex` index, but into the `myindex-2016-04-01` index because
  792. it was rounded by month. This is because the date-index-name-processor overrides the `_index` property of the document.
  793. To see the date-math value of the index supplied in the actual index request which resulted in the above document being
  794. indexed into `myindex-2016-04-01` we can inspect the effects of the processor using a simulate request.
  795. [source,js]
  796. --------------------------------------------------
  797. POST _ingest/pipeline/_simulate
  798. {
  799. "pipeline" :
  800. {
  801. "description": "monthly date-time index naming",
  802. "processors" : [
  803. {
  804. "date_index_name" : {
  805. "field" : "date1",
  806. "index_name_prefix" : "myindex-",
  807. "date_rounding" : "M"
  808. }
  809. }
  810. ]
  811. },
  812. "docs": [
  813. {
  814. "_source": {
  815. "date1": "2016-04-25T12:02:01.789Z"
  816. }
  817. }
  818. ]
  819. }
  820. --------------------------------------------------
  821. // CONSOLE
  822. and the result:
  823. [source,js]
  824. --------------------------------------------------
  825. {
  826. "docs" : [
  827. {
  828. "doc" : {
  829. "_id" : "_id",
  830. "_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>",
  831. "_type" : "_type",
  832. "_source" : {
  833. "date1" : "2016-04-25T12:02:01.789Z"
  834. },
  835. "_ingest" : {
  836. "timestamp" : "2016-11-08T19:43:03.850+0000"
  837. }
  838. }
  839. }
  840. ]
  841. }
  842. --------------------------------------------------
  843. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  844. The above example shows that `_index` was set to `<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>`. Elasticsearch
  845. understands this to mean `2016-04-01` as is explained in the <<date-math-index-names, date math index name documentation>>
  846. [[date-index-name-options]]
  847. .Date index name options
  848. [options="header"]
  849. |======
  850. | Name | Required | Default | Description
  851. | `field` | yes | - | The field to get the date or timestamp from.
  852. | `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date.
  853. | `date_rounding` | yes | - | How to round the date when formatting the date into the index name. Valid values are: `y` (year), `M` (month), `w` (week), `d` (day), `h` (hour), `m` (minute) and `s` (second).
  854. | `date_formats ` | no | yyyy-MM-dd'T'HH:mm:ss.SSSZ | An array of the expected date formats for parsing dates / timestamps in the document being preprocessed. Can be a Joda pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
  855. | `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.
  856. | `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.
  857. | `index_name_format` | no | yyyy-MM-dd | The format to be used when printing the parsed date into the index name. An valid Joda pattern is expected here.
  858. |======
  859. [[fail-processor]]
  860. === Fail Processor
  861. Raises an exception. This is useful for when
  862. you expect a pipeline to fail and want to relay a specific message
  863. to the requester.
  864. [[fail-options]]
  865. .Fail Options
  866. [options="header"]
  867. |======
  868. | Name | Required | Default | Description
  869. | `message` | yes | - | The error message of the `FailException` thrown by the processor
  870. |======
  871. [source,js]
  872. --------------------------------------------------
  873. {
  874. "fail": {
  875. "message": "an error message"
  876. }
  877. }
  878. --------------------------------------------------
  879. // NOTCONSOLE
  880. [[foreach-processor]]
  881. === Foreach Processor
  882. Processes elements in an array of unknown length.
  883. All processors can operate on elements inside an array, but if all elements of an array need to
  884. be processed in the same way, defining a processor for each element becomes cumbersome and tricky
  885. because it is likely that the number of elements in an array is unknown. For this reason the `foreach`
  886. processor exists. By specifying the field holding array elements and a processor that
  887. defines what should happen to each element, array fields can easily be preprocessed.
  888. A processor inside the foreach processor works in the array element context and puts that in the ingest metadata
  889. under the `_ingest._value` key. If the array element is a json object it holds all immediate fields of that json object.
  890. and if the nested object is a value is `_ingest._value` just holds that value. Note that if a processor prior to the
  891. `foreach` processor used `_ingest._value` key then the specified value will not be available to the processor inside
  892. the `foreach` processor. The `foreach` processor does restore the original value, so that value is available to processors
  893. after the `foreach` processor.
  894. Note that any other field from the document are accessible and modifiable like with all other processors. This processor
  895. just puts the current array element being read into `_ingest._value` ingest metadata attribute, so that it may be
  896. pre-processed.
  897. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified,
  898. then it aborts the execution and leaves the array unmodified.
  899. [[foreach-options]]
  900. .Foreach Options
  901. [options="header"]
  902. |======
  903. | Name | Required | Default | Description
  904. | `field` | yes | - | The array field
  905. | `processor` | yes | - | The processor to execute against each field
  906. |======
  907. Assume the following document:
  908. [source,js]
  909. --------------------------------------------------
  910. {
  911. "values" : ["foo", "bar", "baz"]
  912. }
  913. --------------------------------------------------
  914. // NOTCONSOLE
  915. When this `foreach` processor operates on this sample document:
  916. [source,js]
  917. --------------------------------------------------
  918. {
  919. "foreach" : {
  920. "field" : "values",
  921. "processor" : {
  922. "uppercase" : {
  923. "field" : "_ingest._value"
  924. }
  925. }
  926. }
  927. }
  928. --------------------------------------------------
  929. // NOTCONSOLE
  930. Then the document will look like this after preprocessing:
  931. [source,js]
  932. --------------------------------------------------
  933. {
  934. "values" : ["FOO", "BAR", "BAZ"]
  935. }
  936. --------------------------------------------------
  937. // NOTCONSOLE
  938. Let's take a look at another example:
  939. [source,js]
  940. --------------------------------------------------
  941. {
  942. "persons" : [
  943. {
  944. "id" : "1",
  945. "name" : "John Doe"
  946. },
  947. {
  948. "id" : "2",
  949. "name" : "Jane Doe"
  950. }
  951. ]
  952. }
  953. --------------------------------------------------
  954. // NOTCONSOLE
  955. In this case, the `id` field needs to be removed,
  956. so the following `foreach` processor is used:
  957. [source,js]
  958. --------------------------------------------------
  959. {
  960. "foreach" : {
  961. "field" : "persons",
  962. "processor" : {
  963. "remove" : {
  964. "field" : "_ingest._value.id"
  965. }
  966. }
  967. }
  968. }
  969. --------------------------------------------------
  970. // NOTCONSOLE
  971. After preprocessing the result is:
  972. [source,js]
  973. --------------------------------------------------
  974. {
  975. "persons" : [
  976. {
  977. "name" : "John Doe"
  978. },
  979. {
  980. "name" : "Jane Doe"
  981. }
  982. ]
  983. }
  984. --------------------------------------------------
  985. // NOTCONSOLE
  986. The wrapped processor can have a `on_failure` definition.
  987. For example, the `id` field may not exist on all person objects.
  988. Instead of failing the index request, you can use an `on_failure`
  989. block to send the document to the 'failure_index' index for later inspection:
  990. [source,js]
  991. --------------------------------------------------
  992. {
  993. "foreach" : {
  994. "field" : "persons",
  995. "processor" : {
  996. "remove" : {
  997. "field" : "_value.id",
  998. "on_failure" : [
  999. {
  1000. "set" : {
  1001. "field", "_index",
  1002. "value", "failure_index"
  1003. }
  1004. }
  1005. ]
  1006. }
  1007. }
  1008. }
  1009. }
  1010. --------------------------------------------------
  1011. // NOTCONSOLE
  1012. In this example, if the `remove` processor does fail, then
  1013. the array elements that have been processed thus far will
  1014. be updated.
  1015. Another advanced example can be found in the {plugins}/ingest-attachment-with-arrays.html[attachment processor documentation].
  1016. [[grok-processor]]
  1017. === Grok Processor
  1018. Extracts structured fields out of a single text field within a document. You choose which field to
  1019. extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular
  1020. expression that supports aliased expressions that can be reused.
  1021. This tool is perfect for syslog logs, apache and other webserver logs, mysql logs, and in general, any log format
  1022. that is generally written for humans and not computer consumption.
  1023. This processor comes packaged with over
  1024. https://github.com/elastic/elasticsearch/tree/master/modules/ingest-common/src/main/resources/patterns[120 reusable patterns].
  1025. If you need help building patterns to match your logs, you will find the {kibana-ref}/xpack-grokdebugger.html[Grok Debugger] tool quite useful! The Grok Debugger is an {xpack} feature under the Basic License and is therefore *free to use*. The Grok Constructor at <http://grokconstructor.appspot.com/> is also a useful tool.
  1026. [[grok-basics]]
  1027. ==== Grok Basics
  1028. Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
  1029. The regular expression library is Oniguruma, and you can see the full supported regexp syntax
  1030. https://github.com/kkos/oniguruma/blob/master/doc/RE[on the Onigiruma site].
  1031. Grok works by leveraging this regular expression language to allow naming existing patterns and combining them into more
  1032. complex patterns that match your fields.
  1033. The syntax for reusing a grok pattern comes in three forms: `%{SYNTAX:SEMANTIC}`, `%{SYNTAX}`, `%{SYNTAX:SEMANTIC:TYPE}`.
  1034. The `SYNTAX` is the name of the pattern that will match your text. For example, `3.44` will be matched by the `NUMBER`
  1035. pattern and `55.3.244.1` will be matched by the `IP` pattern. The syntax is how you match. `NUMBER` and `IP` are both
  1036. patterns that are provided within the default patterns set.
  1037. The `SEMANTIC` is the identifier you give to the piece of text being matched. For example, `3.44` could be the
  1038. duration of an event, so you could call it simply `duration`. Further, a string `55.3.244.1` might identify
  1039. the `client` making a request.
  1040. The `TYPE` is the type you wish to cast your named field. `int` and `float` are currently the only types supported for coercion.
  1041. For example, you might want to match the following text:
  1042. [source,txt]
  1043. --------------------------------------------------
  1044. 3.44 55.3.244.1
  1045. --------------------------------------------------
  1046. You may know that the message in the example is a number followed by an IP address. You can match this text by using the following
  1047. Grok expression.
  1048. [source,txt]
  1049. --------------------------------------------------
  1050. %{NUMBER:duration} %{IP:client}
  1051. --------------------------------------------------
  1052. [[using-grok]]
  1053. ==== Using the Grok Processor in a Pipeline
  1054. [[grok-options]]
  1055. .Grok Options
  1056. [options="header"]
  1057. |======
  1058. | Name | Required | Default | Description
  1059. | `field` | yes | - | The field to use for grok expression parsing
  1060. | `patterns` | yes | - | An ordered list of grok expression to match and extract named captures with. Returns on the first expression in the list that matches.
  1061. | `pattern_definitions` | no | - | A map of pattern-name and pattern tuples defining custom patterns to be used by the current processor. Patterns matching existing names will override the pre-existing definition.
  1062. | `trace_match` | no | false | when true, `_ingest._grok_match_index` will be inserted into your matched document's metadata with the index into the pattern found in `patterns` that matched.
  1063. | `ignore_missing` | no | false | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1064. |======
  1065. Here is an example of using the provided patterns to extract out and name structured fields from a string field in
  1066. a document.
  1067. [source,js]
  1068. --------------------------------------------------
  1069. {
  1070. "message": "55.3.244.1 GET /index.html 15824 0.043"
  1071. }
  1072. --------------------------------------------------
  1073. // NOTCONSOLE
  1074. The pattern for this could be:
  1075. [source,txt]
  1076. --------------------------------------------------
  1077. %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}
  1078. --------------------------------------------------
  1079. Here is an example pipeline for processing the above document by using Grok:
  1080. [source,js]
  1081. --------------------------------------------------
  1082. {
  1083. "description" : "...",
  1084. "processors": [
  1085. {
  1086. "grok": {
  1087. "field": "message",
  1088. "patterns": ["%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"]
  1089. }
  1090. }
  1091. ]
  1092. }
  1093. --------------------------------------------------
  1094. // NOTCONSOLE
  1095. This pipeline will insert these named captures as new fields within the document, like so:
  1096. [source,js]
  1097. --------------------------------------------------
  1098. {
  1099. "message": "55.3.244.1 GET /index.html 15824 0.043",
  1100. "client": "55.3.244.1",
  1101. "method": "GET",
  1102. "request": "/index.html",
  1103. "bytes": 15824,
  1104. "duration": "0.043"
  1105. }
  1106. --------------------------------------------------
  1107. // NOTCONSOLE
  1108. [[custom-patterns]]
  1109. ==== Custom Patterns and Pattern Files
  1110. The Grok processor comes pre-packaged with a base set of pattern. These patterns may not always have
  1111. what you are looking for. Pattern have a very basic format. Each entry describes has a name and the pattern itself.
  1112. You can add your own patterns to a processor definition under the `pattern_definitions` option.
  1113. Here is an example of a pipeline specifying custom pattern definitions:
  1114. [source,js]
  1115. --------------------------------------------------
  1116. {
  1117. "description" : "...",
  1118. "processors": [
  1119. {
  1120. "grok": {
  1121. "field": "message",
  1122. "patterns": ["my %{FAVORITE_DOG:dog} is colored %{RGB:color}"]
  1123. "pattern_definitions" : {
  1124. "FAVORITE_DOG" : "beagle",
  1125. "RGB" : "RED|GREEN|BLUE"
  1126. }
  1127. }
  1128. }
  1129. ]
  1130. }
  1131. --------------------------------------------------
  1132. // NOTCONSOLE
  1133. [[trace-match]]
  1134. ==== Providing Multiple Match Patterns
  1135. Sometimes one pattern is not enough to capture the potential structure of a field. Let's assume we
  1136. want to match all messages that contain your favorite pet breeds of either cats or dogs. One way to accomplish
  1137. this is to provide two distinct patterns that can be matched, instead of one really complicated expression capturing
  1138. the same `or` behavior.
  1139. Here is an example of such a configuration executed against the simulate API:
  1140. [source,js]
  1141. --------------------------------------------------
  1142. POST _ingest/pipeline/_simulate
  1143. {
  1144. "pipeline": {
  1145. "description" : "parse multiple patterns",
  1146. "processors": [
  1147. {
  1148. "grok": {
  1149. "field": "message",
  1150. "patterns": ["%{FAVORITE_DOG:pet}", "%{FAVORITE_CAT:pet}"],
  1151. "pattern_definitions" : {
  1152. "FAVORITE_DOG" : "beagle",
  1153. "FAVORITE_CAT" : "burmese"
  1154. }
  1155. }
  1156. }
  1157. ]
  1158. },
  1159. "docs":[
  1160. {
  1161. "_source": {
  1162. "message": "I love burmese cats!"
  1163. }
  1164. }
  1165. ]
  1166. }
  1167. --------------------------------------------------
  1168. // CONSOLE
  1169. response:
  1170. [source,js]
  1171. --------------------------------------------------
  1172. {
  1173. "docs": [
  1174. {
  1175. "doc": {
  1176. "_type": "_type",
  1177. "_index": "_index",
  1178. "_id": "_id",
  1179. "_source": {
  1180. "message": "I love burmese cats!",
  1181. "pet": "burmese"
  1182. },
  1183. "_ingest": {
  1184. "timestamp": "2016-11-08T19:43:03.850+0000"
  1185. }
  1186. }
  1187. }
  1188. ]
  1189. }
  1190. --------------------------------------------------
  1191. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  1192. Both patterns will set the field `pet` with the appropriate match, but what if we want to trace which of our
  1193. patterns matched and populated our fields? We can do this with the `trace_match` parameter. Here is the output of
  1194. that same pipeline, but with `"trace_match": true` configured:
  1195. ////
  1196. Hidden setup for example:
  1197. [source,js]
  1198. --------------------------------------------------
  1199. POST _ingest/pipeline/_simulate
  1200. {
  1201. "pipeline": {
  1202. "description" : "parse multiple patterns",
  1203. "processors": [
  1204. {
  1205. "grok": {
  1206. "field": "message",
  1207. "patterns": ["%{FAVORITE_DOG:pet}", "%{FAVORITE_CAT:pet}"],
  1208. "trace_match": true,
  1209. "pattern_definitions" : {
  1210. "FAVORITE_DOG" : "beagle",
  1211. "FAVORITE_CAT" : "burmese"
  1212. }
  1213. }
  1214. }
  1215. ]
  1216. },
  1217. "docs":[
  1218. {
  1219. "_source": {
  1220. "message": "I love burmese cats!"
  1221. }
  1222. }
  1223. ]
  1224. }
  1225. --------------------------------------------------
  1226. // CONSOLE
  1227. ////
  1228. [source,js]
  1229. --------------------------------------------------
  1230. {
  1231. "docs": [
  1232. {
  1233. "doc": {
  1234. "_type": "_type",
  1235. "_index": "_index",
  1236. "_id": "_id",
  1237. "_source": {
  1238. "message": "I love burmese cats!",
  1239. "pet": "burmese"
  1240. },
  1241. "_ingest": {
  1242. "_grok_match_index": "1",
  1243. "timestamp": "2016-11-08T19:43:03.850+0000"
  1244. }
  1245. }
  1246. }
  1247. ]
  1248. }
  1249. --------------------------------------------------
  1250. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  1251. In the above response, you can see that the index of the pattern that matched was `"1"`. This is to say that it was the
  1252. second (index starts at zero) pattern in `patterns` to match.
  1253. This trace metadata enables debugging which of the patterns matched. This information is stored in the ingest
  1254. metadata and will not be indexed.
  1255. [[grok-processor-rest-get]]
  1256. ==== Retrieving patterns from REST endpoint
  1257. The Grok Processor comes packaged with its own REST endpoint for retrieving which patterns the processor is packaged with.
  1258. [source,js]
  1259. --------------------------------------------------
  1260. GET _ingest/processor/grok
  1261. --------------------------------------------------
  1262. // CONSOLE
  1263. The above request will return a response body containing a key-value representation of the built-in patterns dictionary.
  1264. [source,js]
  1265. --------------------------------------------------
  1266. {
  1267. "patterns" : {
  1268. "BACULA_CAPACITY" : "%{INT}{1,3}(,%{INT}{3})*",
  1269. "PATH" : "(?:%{UNIXPATH}|%{WINPATH})",
  1270. ...
  1271. }
  1272. --------------------------------------------------
  1273. // NOTCONSOLE
  1274. This can be useful to reference as the built-in patterns change across versions.
  1275. [[gsub-processor]]
  1276. === Gsub Processor
  1277. Converts a string field by applying a regular expression and a replacement.
  1278. If the field is not a string, the processor will throw an exception.
  1279. [[gsub-options]]
  1280. .Gsub Options
  1281. [options="header"]
  1282. |======
  1283. | Name | Required | Default | Description
  1284. | `field` | yes | - | The field to apply the replacement to
  1285. | `pattern` | yes | - | The pattern to be replaced
  1286. | `replacement` | yes | - | The string to replace the matching patterns with
  1287. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1288. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1289. |======
  1290. [source,js]
  1291. --------------------------------------------------
  1292. {
  1293. "gsub": {
  1294. "field": "field1",
  1295. "pattern": "\.",
  1296. "replacement": "-"
  1297. }
  1298. }
  1299. --------------------------------------------------
  1300. // NOTCONSOLE
  1301. [[join-processor]]
  1302. === Join Processor
  1303. Joins each element of an array into a single string using a separator character between each element.
  1304. Throws an error when the field is not an array.
  1305. [[join-options]]
  1306. .Join Options
  1307. [options="header"]
  1308. |======
  1309. | Name | Required | Default | Description
  1310. | `field` | yes | - | The field to be separated
  1311. | `separator` | yes | - | The separator character
  1312. | `target_field` | no | `field` | The field to assign the joined value to, by default `field` is updated in-place
  1313. |======
  1314. [source,js]
  1315. --------------------------------------------------
  1316. {
  1317. "join": {
  1318. "field": "joined_array_field",
  1319. "separator": "-"
  1320. }
  1321. }
  1322. --------------------------------------------------
  1323. // NOTCONSOLE
  1324. [[json-processor]]
  1325. === JSON Processor
  1326. Converts a JSON string into a structured JSON object.
  1327. [[json-options]]
  1328. .Json Options
  1329. [options="header"]
  1330. |======
  1331. | Name | Required | Default | Description
  1332. | `field` | yes | - | The field to be parsed
  1333. | `target_field` | no | `field` | The field to insert the converted structured object into
  1334. | `add_to_root` | no | false | Flag that forces the serialized json to be injected into the top level of the document. `target_field` must not be set when this option is chosen.
  1335. |======
  1336. Suppose you provide this configuration of the `json` processor:
  1337. [source,js]
  1338. --------------------------------------------------
  1339. {
  1340. "json" : {
  1341. "field" : "string_source",
  1342. "target_field" : "json_target"
  1343. }
  1344. }
  1345. --------------------------------------------------
  1346. // NOTCONSOLE
  1347. If the following document is processed:
  1348. [source,js]
  1349. --------------------------------------------------
  1350. {
  1351. "string_source": "{\"foo\": 2000}"
  1352. }
  1353. --------------------------------------------------
  1354. // NOTCONSOLE
  1355. after the `json` processor operates on it, it will look like:
  1356. [source,js]
  1357. --------------------------------------------------
  1358. {
  1359. "string_source": "{\"foo\": 2000}",
  1360. "json_target": {
  1361. "foo": 2000
  1362. }
  1363. }
  1364. --------------------------------------------------
  1365. // NOTCONSOLE
  1366. If the following configuration is provided, omitting the optional `target_field` setting:
  1367. [source,js]
  1368. --------------------------------------------------
  1369. {
  1370. "json" : {
  1371. "field" : "source_and_target"
  1372. }
  1373. }
  1374. --------------------------------------------------
  1375. // NOTCONSOLE
  1376. then after the `json` processor operates on this document:
  1377. [source,js]
  1378. --------------------------------------------------
  1379. {
  1380. "source_and_target": "{\"foo\": 2000}"
  1381. }
  1382. --------------------------------------------------
  1383. // NOTCONSOLE
  1384. it will look like:
  1385. [source,js]
  1386. --------------------------------------------------
  1387. {
  1388. "source_and_target": {
  1389. "foo": 2000
  1390. }
  1391. }
  1392. --------------------------------------------------
  1393. // NOTCONSOLE
  1394. This illustrates that, unless it is explicitly named in the processor configuration, the `target_field`
  1395. is the same field provided in the required `field` configuration.
  1396. [[kv-processor]]
  1397. === KV Processor
  1398. This processor helps automatically parse messages (or specific event fields) which are of the foo=bar variety.
  1399. For example, if you have a log message which contains `ip=1.2.3.4 error=REFUSED`, you can parse those automatically by configuring:
  1400. [source,js]
  1401. --------------------------------------------------
  1402. {
  1403. "kv": {
  1404. "field": "message",
  1405. "field_split": " ",
  1406. "value_split": "="
  1407. }
  1408. }
  1409. --------------------------------------------------
  1410. // NOTCONSOLE
  1411. [[kv-options]]
  1412. .Kv Options
  1413. [options="header"]
  1414. |======
  1415. | Name | Required | Default | Description
  1416. | `field` | yes | - | The field to be parsed
  1417. | `field_split` | yes | - | Regex pattern to use for splitting key-value pairs
  1418. | `value_split` | yes | - | Regex pattern to use for splitting the key from the value within a key-value pair
  1419. | `target_field` | no | `null` | The field to insert the extracted keys into. Defaults to the root of the document
  1420. | `include_keys` | no | `null` | List of keys to filter and insert into document. Defaults to including all keys
  1421. | `exclude_keys` | no | `null` | List of keys to exclude from document
  1422. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1423. |======
  1424. [[lowercase-processor]]
  1425. === Lowercase Processor
  1426. Converts a string to its lowercase equivalent.
  1427. [[lowercase-options]]
  1428. .Lowercase Options
  1429. [options="header"]
  1430. |======
  1431. | Name | Required | Default | Description
  1432. | `field` | yes | - | The field to make lowercase
  1433. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1434. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1435. |======
  1436. [source,js]
  1437. --------------------------------------------------
  1438. {
  1439. "lowercase": {
  1440. "field": "foo"
  1441. }
  1442. }
  1443. --------------------------------------------------
  1444. // NOTCONSOLE
  1445. [[remove-processor]]
  1446. === Remove Processor
  1447. Removes existing fields. If one field doesn't exist, an exception will be thrown.
  1448. [[remove-options]]
  1449. .Remove Options
  1450. [options="header"]
  1451. |======
  1452. | Name | Required | Default | Description
  1453. | `field` | yes | - | Fields to be removed
  1454. |======
  1455. Here is an example to remove a single field:
  1456. [source,js]
  1457. --------------------------------------------------
  1458. {
  1459. "remove": {
  1460. "field": "foo"
  1461. }
  1462. }
  1463. --------------------------------------------------
  1464. // NOTCONSOLE
  1465. To remove multiple fields, you can use the following query:
  1466. [source,js]
  1467. --------------------------------------------------
  1468. {
  1469. "remove": {
  1470. "field": ["foo", "bar"]
  1471. }
  1472. }
  1473. --------------------------------------------------
  1474. // NOTCONSOLE
  1475. [[rename-processor]]
  1476. === Rename Processor
  1477. Renames an existing field. If the field doesn't exist or the new name is already used, an exception will be thrown.
  1478. [[rename-options]]
  1479. .Rename Options
  1480. [options="header"]
  1481. |======
  1482. | Name | Required | Default | Description
  1483. | `field` | yes | - | The field to be renamed
  1484. | `target_field` | yes | - | The new name of the field
  1485. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  1486. |======
  1487. [source,js]
  1488. --------------------------------------------------
  1489. {
  1490. "rename": {
  1491. "field": "foo",
  1492. "target_field": "foobar"
  1493. }
  1494. }
  1495. --------------------------------------------------
  1496. // NOTCONSOLE
  1497. [[script-processor]]
  1498. === Script Processor
  1499. Allows inline and stored scripts to be executed within ingest pipelines.
  1500. See <<modules-scripting-using, How to use scripts>> to learn more about writing scripts. The Script Processor
  1501. leverages caching of compiled scripts for improved performance. Since the
  1502. script specified within the processor is potentially re-compiled per document, it is important
  1503. to understand how script caching works. To learn more about
  1504. caching see <<modules-scripting-using-caching, Script Caching>>.
  1505. [[script-options]]
  1506. .Script Options
  1507. [options="header"]
  1508. |======
  1509. | Name | Required | Default | Description
  1510. | `lang` | no | "painless" | The scripting language
  1511. | `id` | no | - | The stored script id to refer to
  1512. | `source` | no | - | An inline script to be executed
  1513. | `params` | no | - | Script Parameters
  1514. |======
  1515. One of `id` or `source` options must be provided in order to properly reference a script to execute.
  1516. You can access the current ingest document from within the script context by using the `ctx` variable.
  1517. The following example sets a new field called `field_a_plus_b_times_c` to be the sum of two existing
  1518. numeric fields `field_a` and `field_b` multiplied by the parameter param_c:
  1519. [source,js]
  1520. --------------------------------------------------
  1521. {
  1522. "script": {
  1523. "lang": "painless",
  1524. "source": "ctx.field_a_plus_b_times_c = (ctx.field_a + ctx.field_b) * params.param_c",
  1525. "params": {
  1526. "param_c": 10
  1527. }
  1528. }
  1529. }
  1530. --------------------------------------------------
  1531. // NOTCONSOLE
  1532. It is possible to use the Script Processor to manipulate document metadata like `_index` and `_type` during
  1533. ingestion. Here is an example of an Ingest Pipeline that renames the index and type to `my_index` no matter what
  1534. was provided in the original index request:
  1535. [source,js]
  1536. --------------------------------------------------
  1537. PUT _ingest/pipeline/my_index
  1538. {
  1539. "description": "use index:my_index and type:my_type",
  1540. "processors": [
  1541. {
  1542. "script": {
  1543. "source": " ctx._index = 'my_index'; ctx._type = 'my_type' "
  1544. }
  1545. }
  1546. ]
  1547. }
  1548. --------------------------------------------------
  1549. // CONSOLE
  1550. Using the above pipeline, we can attempt to index a document into the `any_index` index.
  1551. [source,js]
  1552. --------------------------------------------------
  1553. PUT any_index/any_type/1?pipeline=my_index
  1554. {
  1555. "message": "text"
  1556. }
  1557. --------------------------------------------------
  1558. // CONSOLE
  1559. // TEST[continued]
  1560. The response from the above index request:
  1561. [source,js]
  1562. --------------------------------------------------
  1563. {
  1564. "_index": "my_index",
  1565. "_type": "my_type",
  1566. "_id": "1",
  1567. "_version": 1,
  1568. "result": "created",
  1569. "_shards": {
  1570. "total": 2,
  1571. "successful": 1,
  1572. "failed": 0
  1573. },
  1574. "_seq_no": 0,
  1575. "_primary_term": 1,
  1576. }
  1577. --------------------------------------------------
  1578. // TESTRESPONSE
  1579. In the above response, you can see that our document was actually indexed into `my_index` instead of
  1580. `any_index`. This type of manipulation is often convenient in pipelines that have various branches of transformation,
  1581. and depending on the progress made, indexed into different indices.
  1582. [[set-processor]]
  1583. === Set Processor
  1584. Sets one field and associates it with the specified value. If the field already exists,
  1585. its value will be replaced with the provided one.
  1586. [[set-options]]
  1587. .Set Options
  1588. [options="header"]
  1589. |======
  1590. | Name | Required | Default | Description
  1591. | `field` | yes | - | The field to insert, upsert, or update
  1592. | `value` | yes | - | The value to be set for the field
  1593. | `override`| no | true | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched.
  1594. |======
  1595. [source,js]
  1596. --------------------------------------------------
  1597. {
  1598. "set": {
  1599. "field": "field1",
  1600. "value": 582.1
  1601. }
  1602. }
  1603. --------------------------------------------------
  1604. // NOTCONSOLE
  1605. [[split-processor]]
  1606. === Split Processor
  1607. Splits a field into an array using a separator character. Only works on string fields.
  1608. [[split-options]]
  1609. .Split Options
  1610. [options="header"]
  1611. |======
  1612. | Name | Required | Default | Description
  1613. | `field` | yes | - | The field to split
  1614. | `separator` | yes | - | A regex which matches the separator, eg `,` or `\s+`
  1615. | `target_field` | no | `field` | The field to assign the split value to, by default `field` is updated in-place
  1616. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  1617. |======
  1618. [source,js]
  1619. --------------------------------------------------
  1620. {
  1621. "split": {
  1622. "field": "my_field",
  1623. "separator": "\\s+" <1>
  1624. }
  1625. }
  1626. --------------------------------------------------
  1627. // NOTCONSOLE
  1628. <1> Treat all consecutive whitespace characters as a single separator
  1629. [[sort-processor]]
  1630. === Sort Processor
  1631. Sorts the elements of an array ascending or descending. Homogeneous arrays of numbers will be sorted
  1632. numerically, while arrays of strings or heterogeneous arrays of strings + numbers will be sorted lexicographically.
  1633. Throws an error when the field is not an array.
  1634. [[sort-options]]
  1635. .Sort Options
  1636. [options="header"]
  1637. |======
  1638. | Name | Required | Default | Description
  1639. | `field` | yes | - | The field to be sorted
  1640. | `order` | no | `"asc"` | The sort order to use. Accepts `"asc"` or `"desc"`.
  1641. | `target_field` | no | `field` | The field to assign the sorted value to, by default `field` is updated in-place
  1642. |======
  1643. [source,js]
  1644. --------------------------------------------------
  1645. {
  1646. "sort": {
  1647. "field": "field_to_sort",
  1648. "order": "desc"
  1649. }
  1650. }
  1651. --------------------------------------------------
  1652. // NOTCONSOLE
  1653. [[trim-processor]]
  1654. === Trim Processor
  1655. Trims whitespace from field.
  1656. NOTE: This only works on leading and trailing whitespace.
  1657. [[trim-options]]
  1658. .Trim Options
  1659. [options="header"]
  1660. |======
  1661. | Name | Required | Default | Description
  1662. | `field` | yes | - | The string-valued field to trim whitespace from
  1663. | `target_field` | no | `field` | The field to assign the trimmed value to, by default `field` is updated in-place
  1664. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  1665. |======
  1666. [source,js]
  1667. --------------------------------------------------
  1668. {
  1669. "trim": {
  1670. "field": "foo"
  1671. }
  1672. }
  1673. --------------------------------------------------
  1674. // NOTCONSOLE
  1675. [[uppercase-processor]]
  1676. === Uppercase Processor
  1677. Converts a string to its uppercase equivalent.
  1678. [[uppercase-options]]
  1679. .Uppercase Options
  1680. [options="header"]
  1681. |======
  1682. | Name | Required | Default | Description
  1683. | `field` | yes | - | The field to make uppercase
  1684. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1685. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1686. |======
  1687. [source,js]
  1688. --------------------------------------------------
  1689. {
  1690. "uppercase": {
  1691. "field": "foo"
  1692. }
  1693. }
  1694. --------------------------------------------------
  1695. // NOTCONSOLE
  1696. [[dot-expand-processor]]
  1697. === Dot Expander Processor
  1698. Expands a field with dots into an object field. This processor allows fields
  1699. with dots in the name to be accessible by other processors in the pipeline.
  1700. Otherwise these <<accessing-data-in-pipelines,fields>> can't be accessed by any processor.
  1701. [[dot-expender-options]]
  1702. .Dot Expand Options
  1703. [options="header"]
  1704. |======
  1705. | Name | Required | Default | Description
  1706. | `field` | yes | - | The field to expand into an object field
  1707. | `path` | no | - | The field that contains the field to expand. Only required if the field to expand is part another object field, because the `field` option can only understand leaf fields.
  1708. |======
  1709. [source,js]
  1710. --------------------------------------------------
  1711. {
  1712. "dot_expander": {
  1713. "field": "foo.bar"
  1714. }
  1715. }
  1716. --------------------------------------------------
  1717. // NOTCONSOLE
  1718. For example the dot expand processor would turn this document:
  1719. [source,js]
  1720. --------------------------------------------------
  1721. {
  1722. "foo.bar" : "value"
  1723. }
  1724. --------------------------------------------------
  1725. // NOTCONSOLE
  1726. into:
  1727. [source,js]
  1728. --------------------------------------------------
  1729. {
  1730. "foo" : {
  1731. "bar" : "value"
  1732. }
  1733. }
  1734. --------------------------------------------------
  1735. // NOTCONSOLE
  1736. If there is already a `bar` field nested under `foo` then
  1737. this processor merges the `foo.bar` field into it. If the field is
  1738. a scalar value then it will turn that field into an array field.
  1739. For example, the following document:
  1740. [source,js]
  1741. --------------------------------------------------
  1742. {
  1743. "foo.bar" : "value2",
  1744. "foo" : {
  1745. "bar" : "value1"
  1746. }
  1747. }
  1748. --------------------------------------------------
  1749. // NOTCONSOLE
  1750. is transformed by the `dot_expander` processor into:
  1751. [source,js]
  1752. --------------------------------------------------
  1753. {
  1754. "foo" : {
  1755. "bar" : ["value1", "value2"]
  1756. }
  1757. }
  1758. --------------------------------------------------
  1759. // NOTCONSOLE
  1760. If any field outside of the leaf field conflicts with a pre-existing field of the same name,
  1761. then that field needs to be renamed first.
  1762. Consider the following document:
  1763. [source,js]
  1764. --------------------------------------------------
  1765. {
  1766. "foo": "value1",
  1767. "foo.bar": "value2"
  1768. }
  1769. --------------------------------------------------
  1770. // NOTCONSOLE
  1771. Then the `foo` needs to be renamed first before the `dot_expander`
  1772. processor is applied. So in order for the `foo.bar` field to properly
  1773. be expanded into the `bar` field under the `foo` field the following
  1774. pipeline should be used:
  1775. [source,js]
  1776. --------------------------------------------------
  1777. {
  1778. "processors" : [
  1779. {
  1780. "rename" : {
  1781. "field" : "foo",
  1782. "target_field" : "foo.bar""
  1783. }
  1784. },
  1785. {
  1786. "dot_expander": {
  1787. "field": "foo.bar"
  1788. }
  1789. }
  1790. ]
  1791. }
  1792. --------------------------------------------------
  1793. // NOTCONSOLE
  1794. The reason for this is that Ingest doesn't know how to automatically cast
  1795. a scalar field to an object field.
  1796. [[urldecode-processor]]
  1797. === URL Decode Processor
  1798. URL-decodes a string
  1799. [[urldecode-options]]
  1800. .URL Decode Options
  1801. [options="header"]
  1802. |======
  1803. | Name | Required | Default | Description
  1804. | `field` | yes | - | The field to decode
  1805. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1806. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1807. |======
  1808. [source,js]
  1809. --------------------------------------------------
  1810. {
  1811. "urldecode": {
  1812. "field": "my_url_to_decode"
  1813. }
  1814. }
  1815. --------------------------------------------------
  1816. // NOTCONSOLE