ingest-node.asciidoc 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623
  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": "_doc",
  214. "_id": "id",
  215. "_source": {
  216. "foo": "bar"
  217. }
  218. },
  219. {
  220. "_index": "index",
  221. "_type": "_doc",
  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": "_doc",
  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": "_doc",
  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": "_doc",
  302. "_id": "id",
  303. "_source": {
  304. "foo": "bar"
  305. }
  306. },
  307. {
  308. "_index": "index",
  309. "_type": "_doc",
  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": "_doc",
  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": "_doc",
  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": "_doc",
  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": "_doc",
  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. Dynamic field names are also supported. This example sets the field named after the
  499. value of `service` to the value of the field `code`:
  500. [source,js]
  501. --------------------------------------------------
  502. {
  503. "set": {
  504. "field": "{{service}}",
  505. "value": "{{code}}"
  506. }
  507. }
  508. --------------------------------------------------
  509. // NOTCONSOLE
  510. [[handling-failure-in-pipelines]]
  511. == Handling Failures in Pipelines
  512. In its simplest use case, a pipeline defines a list of processors that
  513. are executed sequentially, and processing halts at the first exception. This
  514. behavior may not be desirable when failures are expected. For example, you may have logs
  515. that don't match the specified grok expression. Instead of halting execution, you may
  516. want to index such documents into a separate index.
  517. To enable this behavior, you can use the `on_failure` parameter. The `on_failure` parameter
  518. defines a list of processors to be executed immediately following the failed processor.
  519. You can specify this parameter at the pipeline level, as well as at the processor
  520. level. If a processor specifies an `on_failure` configuration, whether
  521. it is empty or not, any exceptions that are thrown by the processor are caught, and the
  522. pipeline continues executing the remaining processors. Because you can define further processors
  523. within the scope of an `on_failure` statement, you can nest failure handling.
  524. The following example defines a pipeline that renames the `foo` field in
  525. the processed document to `bar`. If the document does not contain the `foo` field, the processor
  526. attaches an error message to the document for later analysis within
  527. Elasticsearch.
  528. [source,js]
  529. --------------------------------------------------
  530. {
  531. "description" : "my first pipeline with handled exceptions",
  532. "processors" : [
  533. {
  534. "rename" : {
  535. "field" : "foo",
  536. "target_field" : "bar",
  537. "on_failure" : [
  538. {
  539. "set" : {
  540. "field" : "error",
  541. "value" : "field \"foo\" does not exist, cannot rename to \"bar\""
  542. }
  543. }
  544. ]
  545. }
  546. }
  547. ]
  548. }
  549. --------------------------------------------------
  550. // NOTCONSOLE
  551. The following example defines an `on_failure` block on a whole pipeline to change
  552. the index to which failed documents get sent.
  553. [source,js]
  554. --------------------------------------------------
  555. {
  556. "description" : "my first pipeline with handled exceptions",
  557. "processors" : [ ... ],
  558. "on_failure" : [
  559. {
  560. "set" : {
  561. "field" : "_index",
  562. "value" : "failed-{{ _index }}"
  563. }
  564. }
  565. ]
  566. }
  567. --------------------------------------------------
  568. // NOTCONSOLE
  569. Alternatively instead of defining behaviour in case of processor failure, it is also possible
  570. to ignore a failure and continue with the next processor by specifying the `ignore_failure` setting.
  571. In case in the example below the field `foo` doesn't exist the failure will be caught and the pipeline
  572. continues to execute, which in this case means that the pipeline does nothing.
  573. [source,js]
  574. --------------------------------------------------
  575. {
  576. "description" : "my first pipeline with handled exceptions",
  577. "processors" : [
  578. {
  579. "rename" : {
  580. "field" : "foo",
  581. "target_field" : "bar",
  582. "ignore_failure" : true
  583. }
  584. }
  585. ]
  586. }
  587. --------------------------------------------------
  588. // NOTCONSOLE
  589. The `ignore_failure` can be set on any processor and defaults to `false`.
  590. [float]
  591. [[accessing-error-metadata]]
  592. === Accessing Error Metadata From Processors Handling Exceptions
  593. You may want to retrieve the actual error message that was thrown
  594. by a failed processor. To do so you can access metadata fields called
  595. `on_failure_message`, `on_failure_processor_type`, and `on_failure_processor_tag`. These fields are only accessible
  596. from within the context of an `on_failure` block.
  597. Here is an updated version of the example that you
  598. saw earlier. But instead of setting the error message manually, the example leverages the `on_failure_message`
  599. metadata field to provide the error message.
  600. [source,js]
  601. --------------------------------------------------
  602. {
  603. "description" : "my first pipeline with handled exceptions",
  604. "processors" : [
  605. {
  606. "rename" : {
  607. "field" : "foo",
  608. "to" : "bar",
  609. "on_failure" : [
  610. {
  611. "set" : {
  612. "field" : "error",
  613. "value" : "{{ _ingest.on_failure_message }}"
  614. }
  615. }
  616. ]
  617. }
  618. }
  619. ]
  620. }
  621. --------------------------------------------------
  622. // NOTCONSOLE
  623. [[ingest-processors]]
  624. == Processors
  625. All processors are defined in the following way within a pipeline definition:
  626. [source,js]
  627. --------------------------------------------------
  628. {
  629. "PROCESSOR_NAME" : {
  630. ... processor configuration options ...
  631. }
  632. }
  633. --------------------------------------------------
  634. // NOTCONSOLE
  635. Each processor defines its own configuration parameters, but all processors have
  636. the ability to declare `tag`, `on_failure` and `if` fields. These fields are optional.
  637. A `tag` is simply a string identifier of the specific instantiation of a certain
  638. processor in a pipeline. The `tag` field does not affect the processor's behavior,
  639. but is very useful for bookkeeping and tracing errors to specific processors.
  640. The `if` field must contain a script that returns a boolean value. If the script evaluates to `true`
  641. then the processor will be executed for the given document otherwise it will be skipped.
  642. The `if` field takes an object with the script fields defined in <<script-processor, script-options>>
  643. and accesses a read only version of the document via the same `ctx` variable used by scripts in the
  644. <<script-processor>>.
  645. [source,js]
  646. --------------------------------------------------
  647. {
  648. "set": {
  649. "if": "ctx.bar == 'expectedValue'",
  650. "field": "foo",
  651. "value": "bar"
  652. }
  653. }
  654. --------------------------------------------------
  655. // NOTCONSOLE
  656. See <<handling-failure-in-pipelines>> to learn more about the `on_failure` field and error handling in pipelines.
  657. The <<ingest-info,node info API>> can be used to figure out what processors are available in a cluster.
  658. The <<ingest-info,node info API>> will provide a per node list of what processors are available.
  659. Custom processors must be installed on all nodes. The put pipeline API will fail if a processor specified in a pipeline
  660. doesn't exist on all nodes. If you rely on custom processor plugins make sure to mark these plugins as mandatory by adding
  661. `plugin.mandatory` setting to the `config/elasticsearch.yml` file, for example:
  662. [source,yaml]
  663. --------------------------------------------------
  664. plugin.mandatory: ingest-attachment,ingest-geoip
  665. --------------------------------------------------
  666. A node will not start if either of these plugins are not available.
  667. The <<ingest-stats,node stats API>> can be used to fetch ingest usage statistics, globally and on a per
  668. pipeline basis. Useful to find out which pipelines are used the most or spent the most time on preprocessing.
  669. [float]
  670. === Ingest Processor Plugins
  671. Additional ingest processors can be implemented and installed as Elasticsearch {plugins}/intro.html[plugins].
  672. See {plugins}/ingest.html[Ingest plugins] for information about the available ingest plugins.
  673. [[append-processor]]
  674. === Append Processor
  675. Appends one or more values to an existing array if the field already exists and it is an array.
  676. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar.
  677. Creates an array containing the provided values if the field doesn't exist.
  678. Accepts a single value or an array of values.
  679. [[append-options]]
  680. .Append Options
  681. [options="header"]
  682. |======
  683. | Name | Required | Default | Description
  684. | `field` | yes | - | The field to be appended to. Supports <<accessing-template-fields,template snippets>>.
  685. | `value` | yes | - | The value to be appended. Supports <<accessing-template-fields,template snippets>>.
  686. include::ingest-node-common-processor.asciidoc[]
  687. |======
  688. [source,js]
  689. --------------------------------------------------
  690. {
  691. "append": {
  692. "field": "tags",
  693. "value": ["production", "{{app}}", "{{owner}}"]
  694. }
  695. }
  696. --------------------------------------------------
  697. // NOTCONSOLE
  698. [[bytes-processor]]
  699. === Bytes Processor
  700. Converts a human readable byte value (e.g. 1kb) to its value in bytes (e.g. 1024).
  701. Supported human readable units are "b", "kb", "mb", "gb", "tb", "pb" case insensitive. An error will occur if
  702. the field is not a supported format or resultant value exceeds 2^63.
  703. [[bytes-options]]
  704. .Bytes Options
  705. [options="header"]
  706. |======
  707. | Name | Required | Default | Description
  708. | `field` | yes | - | The field to convert
  709. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  710. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  711. include::ingest-node-common-processor.asciidoc[]
  712. |======
  713. [source,js]
  714. --------------------------------------------------
  715. {
  716. "bytes": {
  717. "field": "file.size"
  718. }
  719. }
  720. --------------------------------------------------
  721. // NOTCONSOLE
  722. [[convert-processor]]
  723. === Convert Processor
  724. Converts a field in the currently ingested document to a different type, such as converting a string to an integer.
  725. If the field value is an array, all members will be converted.
  726. The supported types include: `integer`, `long`, `float`, `double`, `string`, `boolean`, and `auto`.
  727. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  728. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  729. Specifying `auto` will attempt to convert the string-valued `field` into the closest non-string type.
  730. For example, a field whose value is `"true"` will be converted to its respective boolean type: `true`. Do note
  731. that float takes precedence of double in `auto`. A value of `"242.15"` will "automatically" be converted to
  732. `242.15` of type `float`. If a provided field cannot be appropriately converted, the Convert Processor will
  733. still process successfully and leave the field value as-is. In such a case, `target_field` will
  734. still be updated with the unconverted field value.
  735. [[convert-options]]
  736. .Convert Options
  737. [options="header"]
  738. |======
  739. | Name | Required | Default | Description
  740. | `field` | yes | - | The field whose value is to be converted
  741. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  742. | `type` | yes | - | The type to convert the existing value to
  743. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  744. include::ingest-node-common-processor.asciidoc[]
  745. |======
  746. [source,js]
  747. --------------------------------------------------
  748. PUT _ingest/pipeline/my-pipeline-id
  749. {
  750. "description": "converts the content of the id field to an integer",
  751. "processors" : [
  752. {
  753. "convert" : {
  754. "field" : "id",
  755. "type": "integer"
  756. }
  757. }
  758. ]
  759. }
  760. --------------------------------------------------
  761. // NOTCONSOLE
  762. [[date-processor]]
  763. === Date Processor
  764. Parses dates from fields, and then uses the date or timestamp as the timestamp for the document.
  765. By default, the date processor adds the parsed date as a new field called `@timestamp`. You can specify a
  766. different field by setting the `target_field` configuration parameter. Multiple date formats are supported
  767. as part of the same date processor definition. They will be used sequentially to attempt parsing the date field,
  768. in the same order they were defined as part of the processor definition.
  769. [[date-options]]
  770. .Date options
  771. [options="header"]
  772. |======
  773. | Name | Required | Default | Description
  774. | `field` | yes | - | The field to get the date from.
  775. | `target_field` | no | @timestamp | The field that will hold the parsed date.
  776. | `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.
  777. | `timezone` | no | UTC | The timezone to use when parsing the date. Supports <<accessing-template-fields,template snippets>>.
  778. | `locale` | no | ENGLISH | The locale to use when parsing the date, relevant when parsing month names or week days. Supports <<accessing-template-fields,template snippets>>.
  779. include::ingest-node-common-processor.asciidoc[]
  780. |======
  781. Here is an example that adds the parsed date to the `timestamp` field based on the `initial_date` field:
  782. [source,js]
  783. --------------------------------------------------
  784. {
  785. "description" : "...",
  786. "processors" : [
  787. {
  788. "date" : {
  789. "field" : "initial_date",
  790. "target_field" : "timestamp",
  791. "formats" : ["dd/MM/yyyy hh:mm:ss"],
  792. "timezone" : "Europe/Amsterdam"
  793. }
  794. }
  795. ]
  796. }
  797. --------------------------------------------------
  798. // NOTCONSOLE
  799. The `timezone` and `locale` processor parameters are templated. This means that their values can be
  800. extracted from fields within documents. The example below shows how to extract the locale/timezone
  801. details from existing fields, `my_timezone` and `my_locale`, in the ingested document that contain
  802. the timezone and locale values.
  803. [source,js]
  804. --------------------------------------------------
  805. {
  806. "description" : "...",
  807. "processors" : [
  808. {
  809. "date" : {
  810. "field" : "initial_date",
  811. "target_field" : "timestamp",
  812. "formats" : ["ISO8601"],
  813. "timezone" : "{{my_timezone}}",
  814. "locale" : "{{my_locale}}"
  815. }
  816. }
  817. ]
  818. }
  819. --------------------------------------------------
  820. // NOTCONSOLE
  821. [[date-index-name-processor]]
  822. === Date Index Name Processor
  823. The purpose of this processor is to point documents to the right time based index based
  824. on a date or timestamp field in a document by using the <<date-math-index-names, date math index name support>>.
  825. The processor sets the `_index` meta field with a date math index name expression based on the provided index name
  826. prefix, a date or timestamp field in the documents being processed and the provided date rounding.
  827. First, this processor fetches the date or timestamp from a field in the document being processed. Optionally,
  828. date formatting can be configured on how the field's value should be parsed into a date. Then this date,
  829. the provided index name prefix and the provided date rounding get formatted into a date math index name expression.
  830. Also here optionally date formatting can be specified on how the date should be formatted into a date math index name
  831. expression.
  832. An example pipeline that points documents to a monthly index that starts with a `myindex-` prefix based on a
  833. date in the `date1` field:
  834. [source,js]
  835. --------------------------------------------------
  836. PUT _ingest/pipeline/monthlyindex
  837. {
  838. "description": "monthly date-time index naming",
  839. "processors" : [
  840. {
  841. "date_index_name" : {
  842. "field" : "date1",
  843. "index_name_prefix" : "myindex-",
  844. "date_rounding" : "M"
  845. }
  846. }
  847. ]
  848. }
  849. --------------------------------------------------
  850. // CONSOLE
  851. Using that pipeline for an index request:
  852. [source,js]
  853. --------------------------------------------------
  854. PUT /myindex/_doc/1?pipeline=monthlyindex
  855. {
  856. "date1" : "2016-04-25T12:02:01.789Z"
  857. }
  858. --------------------------------------------------
  859. // CONSOLE
  860. // TEST[continued]
  861. [source,js]
  862. --------------------------------------------------
  863. {
  864. "_index" : "myindex-2016-04-01",
  865. "_type" : "_doc",
  866. "_id" : "1",
  867. "_version" : 1,
  868. "result" : "created",
  869. "_shards" : {
  870. "total" : 2,
  871. "successful" : 1,
  872. "failed" : 0
  873. },
  874. "_seq_no" : 0,
  875. "_primary_term" : 1
  876. }
  877. --------------------------------------------------
  878. // TESTRESPONSE
  879. The above request will not index this document into the `myindex` index, but into the `myindex-2016-04-01` index because
  880. it was rounded by month. This is because the date-index-name-processor overrides the `_index` property of the document.
  881. To see the date-math value of the index supplied in the actual index request which resulted in the above document being
  882. indexed into `myindex-2016-04-01` we can inspect the effects of the processor using a simulate request.
  883. [source,js]
  884. --------------------------------------------------
  885. POST _ingest/pipeline/_simulate
  886. {
  887. "pipeline" :
  888. {
  889. "description": "monthly date-time index naming",
  890. "processors" : [
  891. {
  892. "date_index_name" : {
  893. "field" : "date1",
  894. "index_name_prefix" : "myindex-",
  895. "date_rounding" : "M"
  896. }
  897. }
  898. ]
  899. },
  900. "docs": [
  901. {
  902. "_source": {
  903. "date1": "2016-04-25T12:02:01.789Z"
  904. }
  905. }
  906. ]
  907. }
  908. --------------------------------------------------
  909. // CONSOLE
  910. and the result:
  911. [source,js]
  912. --------------------------------------------------
  913. {
  914. "docs" : [
  915. {
  916. "doc" : {
  917. "_id" : "_id",
  918. "_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>",
  919. "_type" : "_type",
  920. "_source" : {
  921. "date1" : "2016-04-25T12:02:01.789Z"
  922. },
  923. "_ingest" : {
  924. "timestamp" : "2016-11-08T19:43:03.850+0000"
  925. }
  926. }
  927. }
  928. ]
  929. }
  930. --------------------------------------------------
  931. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  932. The above example shows that `_index` was set to `<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>`. Elasticsearch
  933. understands this to mean `2016-04-01` as is explained in the <<date-math-index-names, date math index name documentation>>
  934. [[date-index-name-options]]
  935. .Date index name options
  936. [options="header"]
  937. |======
  938. | Name | Required | Default | Description
  939. | `field` | yes | - | The field to get the date or timestamp from.
  940. | `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date. Supports <<accessing-template-fields,template snippets>>.
  941. | `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). Supports <<accessing-template-fields,template snippets>>.
  942. | `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.
  943. | `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.
  944. | `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.
  945. | `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. Supports <<accessing-template-fields,template snippets>>.
  946. include::ingest-node-common-processor.asciidoc[]
  947. |======
  948. [[dissect-processor]]
  949. === Dissect Processor
  950. Similar to the <<grok-processor,Grok Processor>>, dissect also extracts structured fields out of a single text field
  951. within a document. However unlike the <<grok-processor,Grok Processor>>, dissect does not use
  952. https://en.wikipedia.org/wiki/Regular_expression[Regular Expressions]. This allows dissect's syntax to be simple and for
  953. some cases faster than the <<grok-processor,Grok Processor>>.
  954. Dissect matches a single text field against a defined pattern.
  955. For example the following pattern:
  956. [source,txt]
  957. --------------------------------------------------
  958. %{clientip} %{ident} %{auth} [%{@timestamp}] \"%{verb} %{request} HTTP/%{httpversion}\" %{status} %{size}
  959. --------------------------------------------------
  960. will match a log line of this format:
  961. [source,txt]
  962. --------------------------------------------------
  963. 1.2.3.4 - - [30/Apr/1998:22:00:52 +0000] \"GET /english/venues/cities/images/montpellier/18.gif HTTP/1.0\" 200 3171
  964. --------------------------------------------------
  965. and result in a document with the following fields:
  966. [source,js]
  967. --------------------------------------------------
  968. "doc": {
  969. "_index": "_index",
  970. "_type": "_type",
  971. "_id": "_id",
  972. "_source": {
  973. "request": "/english/venues/cities/images/montpellier/18.gif",
  974. "auth": "-",
  975. "ident": "-",
  976. "verb": "GET",
  977. "@timestamp": "30/Apr/1998:22:00:52 +0000",
  978. "size": "3171",
  979. "clientip": "1.2.3.4",
  980. "httpversion": "1.0",
  981. "status": "200"
  982. }
  983. }
  984. --------------------------------------------------
  985. // NOTCONSOLE
  986. A dissect pattern is defined by the parts of the string that will be discarded. In the example above the first part
  987. to be discarded is a single space. Dissect finds this space, then assigns the value of `clientip` is everything up
  988. until that space.
  989. Later dissect matches the `[` and then `]` and then assigns `@timestamp` to everything in-between `[` and `]`.
  990. Paying special attention the parts of the string to discard will help build successful dissect patterns.
  991. Successful matches require all keys in a pattern to have a value. If any of the `%{keyname}` defined in the pattern do
  992. not have a value, then an exception is thrown and may be handled by the <<handling-failure-in-pipelines,on_falure>> directive.
  993. An empty key `%{}` or a <<dissect-modifier-named-skip-key, named skip key>> can be used to match values, but exclude the value from
  994. the final document. All matched values are represented as string data types. The <<convert-processor, convert processor>>
  995. may be used to convert to expected data type.
  996. Dissect also supports <<dissect-key-modifiers,key modifiers>> that can change dissect's default
  997. behavior. For example you can instruct dissect to ignore certain fields, append fields, skip over padding, etc.
  998. See <<dissect-key-modifiers, below>> for more information.
  999. [[dissect-options]]
  1000. .Dissect Options
  1001. [options="header"]
  1002. |======
  1003. | Name | Required | Default | Description
  1004. | `field` | yes | - | The field to dissect
  1005. | `pattern` | yes | - | The pattern to apply to the field
  1006. | `append_separator`| no | "" (empty string) | The character(s) that separate the appended fields.
  1007. | `ignore_missing` | no | false | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1008. include::ingest-node-common-processor.asciidoc[]
  1009. |======
  1010. [source,js]
  1011. --------------------------------------------------
  1012. {
  1013. "dissect": {
  1014. "field": "message",
  1015. "pattern" : "%{clientip} %{ident} %{auth} [%{@timestamp}] \"%{verb} %{request} HTTP/%{httpversion}\" %{status} %{size}"
  1016. }
  1017. }
  1018. --------------------------------------------------
  1019. // NOTCONSOLE
  1020. [[dissect-key-modifiers]]
  1021. ==== Dissect key modifiers
  1022. Key modifiers can change the default behavior for dissection. Key modifiers may be found on the left or right
  1023. of the `%{keyname}` always inside the `%{` and `}`. For example `%{+keyname ->}` has the append and right padding
  1024. modifiers.
  1025. .Dissect Key Modifiers
  1026. [options="header"]
  1027. |======
  1028. | Modifier | Name | Position | Example | Description | Details
  1029. | `->` | Skip right padding | (far) right | `%{keyname1->}` | Skips any repeated characters to the right | <<dissect-modifier-skip-right-padding,link>>
  1030. | `+` | Append | left | `%{+keyname} %{+keyname}` | Appends two or more fields together | <<dissect-modifier-append-key,link>>
  1031. | `+` with `/n` | Append with order | left and right | `%{+keyname/2} %{+keyname/1}` | Appends two or more fields together in the order specified | <<dissect-modifier-append-key-with-order,link>>
  1032. | `?` | Named skip key | left | `%{?ignoreme}` | Skips the matched value in the output. Same behavior as `%{}`| <<dissect-modifier-named-skip-key,link>>
  1033. | `*` and `&` | Reference keys | left | `%{*r1} %{&r1}` | Sets the output key as value of `*` and output value of `&` | <<dissect-modifier-reference-keys,link>>
  1034. |======
  1035. [[dissect-modifier-skip-right-padding]]
  1036. ===== Right padding modifier (`->`)
  1037. The algorithm that performs the dissection is very strict in that it requires all characters in the pattern to match
  1038. the source string. For example, the pattern `%{fookey} %{barkey}` (1 space), will match the string "foo{nbsp}bar"
  1039. (1 space), but will not match the string "foo{nbsp}{nbsp}bar" (2 spaces) since the pattern has only 1 space and the
  1040. source string has 2 spaces.
  1041. The right padding modifier helps with this case. Adding the right padding modifier to the pattern `%{fookey->} %{barkey}`,
  1042. It will now will match "foo{nbsp}bar" (1 space) and "foo{nbsp}{nbsp}bar" (2 spaces)
  1043. and even "foo{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}bar" (10 spaces).
  1044. Use the right padding modifier to allow for repetition of the characters after a `%{keyname->}`.
  1045. The right padding modifier may be placed on any key with any other modifiers. It should always be the furthest right
  1046. modifier. For example: `%{+keyname/1->}` and `%{->}`
  1047. Right padding modifier example
  1048. |======
  1049. | *Pattern* | `%{ts->} %{level}`
  1050. | *Input* | 1998-08-10T17:15:42,466{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}WARN
  1051. | *Result* a|
  1052. * ts = 1998-08-10T17:15:42,466
  1053. * level = WARN
  1054. |======
  1055. The right padding modifier may be used with an empty key to help skip unwanted data. For example, the same input string, but wrapped with brackets requires the use of an empty right padded key to achieve the same result.
  1056. Right padding modifier with empty key example
  1057. |======
  1058. | *Pattern* | `[%{ts}]%{->}[%{level}]`
  1059. | *Input* | [1998-08-10T17:15:42,466]{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}[WARN]
  1060. | *Result* a|
  1061. * ts = 1998-08-10T17:15:42,466
  1062. * level = WARN
  1063. |======
  1064. ===== Append modifier (`+`)
  1065. [[dissect-modifier-append-key]]
  1066. Dissect supports appending two or more results together for the output.
  1067. Values are appended left to right. An append separator can be specified.
  1068. In this example the append_separator is defined as a space.
  1069. Append modifier example
  1070. |======
  1071. | *Pattern* | `%{+name} %{+name} %{+name} %{+name}`
  1072. | *Input* | john jacob jingleheimer schmidt
  1073. | *Result* a|
  1074. * name = john jacob jingleheimer schmidt
  1075. |======
  1076. ===== Append with order modifier (`+` and `/n`)
  1077. [[dissect-modifier-append-key-with-order]]
  1078. Dissect supports appending two or more results together for the output.
  1079. Values are appended based on the order defined (`/n`). An append separator can be specified.
  1080. In this example the append_separator is defined as a comma.
  1081. Append with order modifier example
  1082. |======
  1083. | *Pattern* | `%{+name/2} %{+name/4} %{+name/3} %{+name/1}`
  1084. | *Input* | john jacob jingleheimer schmidt
  1085. | *Result* a|
  1086. * name = schmidt,john,jingleheimer,jacob
  1087. |======
  1088. ===== Named skip key (`?`)
  1089. [[dissect-modifier-named-skip-key]]
  1090. Dissect supports ignoring matches in the final result. This can be done with an empty key `%{}`, but for readability
  1091. it may be desired to give that empty key a name.
  1092. Named skip key modifier example
  1093. |======
  1094. | *Pattern* | `%{clientip} %{?ident} %{?auth} [%{@timestamp}]`
  1095. | *Input* | 1.2.3.4 - - [30/Apr/1998:22:00:52 +0000]
  1096. | *Result* a|
  1097. * ip = 1.2.3.4
  1098. * @timestamp = 30/Apr/1998:22:00:52 +0000
  1099. |======
  1100. ===== Reference keys (`*` and `&`)
  1101. [[dissect-modifier-reference-keys]]
  1102. Dissect support using parsed values as the key/value pairings for the structured content. Imagine a system that
  1103. partially logs in key/value pairs. Reference keys allow you to maintain that key/value relationship.
  1104. Reference key modifier example
  1105. |======
  1106. | *Pattern* | `[%{ts}] [%{level}] %{*p1}:%{&p1} %{*p2}:%{&p2}`
  1107. | *Input* | [2018-08-10T17:15:42,466] [ERR] ip:1.2.3.4 error:REFUSED
  1108. | *Result* a|
  1109. * ts = 1998-08-10T17:15:42,466
  1110. * level = ERR
  1111. * ip = 1.2.3.4
  1112. * error = REFUSED
  1113. |======
  1114. [[drop-processor]]
  1115. === Drop Processor
  1116. Drops the document without raising any errors. This is useful to prevent the document from
  1117. getting indexed based on some condition.
  1118. [[drop-options]]
  1119. .Drop Options
  1120. [options="header"]
  1121. |======
  1122. | Name | Required | Default | Description
  1123. include::ingest-node-common-processor.asciidoc[]
  1124. |======
  1125. [source,js]
  1126. --------------------------------------------------
  1127. {
  1128. "drop": {
  1129. "if" : "ctx.network_name == 'Guest'"
  1130. }
  1131. }
  1132. --------------------------------------------------
  1133. // NOTCONSOLE
  1134. [[dot-expand-processor]]
  1135. === Dot Expander Processor
  1136. Expands a field with dots into an object field. This processor allows fields
  1137. with dots in the name to be accessible by other processors in the pipeline.
  1138. Otherwise these <<accessing-data-in-pipelines,fields>> can't be accessed by any processor.
  1139. [[dot-expender-options]]
  1140. .Dot Expand Options
  1141. [options="header"]
  1142. |======
  1143. | Name | Required | Default | Description
  1144. | `field` | yes | - | The field to expand into an object field
  1145. | `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.
  1146. include::ingest-node-common-processor.asciidoc[]
  1147. |======
  1148. [source,js]
  1149. --------------------------------------------------
  1150. {
  1151. "dot_expander": {
  1152. "field": "foo.bar"
  1153. }
  1154. }
  1155. --------------------------------------------------
  1156. // NOTCONSOLE
  1157. For example the dot expand processor would turn this document:
  1158. [source,js]
  1159. --------------------------------------------------
  1160. {
  1161. "foo.bar" : "value"
  1162. }
  1163. --------------------------------------------------
  1164. // NOTCONSOLE
  1165. into:
  1166. [source,js]
  1167. --------------------------------------------------
  1168. {
  1169. "foo" : {
  1170. "bar" : "value"
  1171. }
  1172. }
  1173. --------------------------------------------------
  1174. // NOTCONSOLE
  1175. If there is already a `bar` field nested under `foo` then
  1176. this processor merges the `foo.bar` field into it. If the field is
  1177. a scalar value then it will turn that field into an array field.
  1178. For example, the following document:
  1179. [source,js]
  1180. --------------------------------------------------
  1181. {
  1182. "foo.bar" : "value2",
  1183. "foo" : {
  1184. "bar" : "value1"
  1185. }
  1186. }
  1187. --------------------------------------------------
  1188. // NOTCONSOLE
  1189. is transformed by the `dot_expander` processor into:
  1190. [source,js]
  1191. --------------------------------------------------
  1192. {
  1193. "foo" : {
  1194. "bar" : ["value1", "value2"]
  1195. }
  1196. }
  1197. --------------------------------------------------
  1198. // NOTCONSOLE
  1199. If any field outside of the leaf field conflicts with a pre-existing field of the same name,
  1200. then that field needs to be renamed first.
  1201. Consider the following document:
  1202. [source,js]
  1203. --------------------------------------------------
  1204. {
  1205. "foo": "value1",
  1206. "foo.bar": "value2"
  1207. }
  1208. --------------------------------------------------
  1209. // NOTCONSOLE
  1210. Then the `foo` needs to be renamed first before the `dot_expander`
  1211. processor is applied. So in order for the `foo.bar` field to properly
  1212. be expanded into the `bar` field under the `foo` field the following
  1213. pipeline should be used:
  1214. [source,js]
  1215. --------------------------------------------------
  1216. {
  1217. "processors" : [
  1218. {
  1219. "rename" : {
  1220. "field" : "foo",
  1221. "target_field" : "foo.bar""
  1222. }
  1223. },
  1224. {
  1225. "dot_expander": {
  1226. "field": "foo.bar"
  1227. }
  1228. }
  1229. ]
  1230. }
  1231. --------------------------------------------------
  1232. // NOTCONSOLE
  1233. The reason for this is that Ingest doesn't know how to automatically cast
  1234. a scalar field to an object field.
  1235. [[fail-processor]]
  1236. === Fail Processor
  1237. Raises an exception. This is useful for when
  1238. you expect a pipeline to fail and want to relay a specific message
  1239. to the requester.
  1240. [[fail-options]]
  1241. .Fail Options
  1242. [options="header"]
  1243. |======
  1244. | Name | Required | Default | Description
  1245. | `message` | yes | - | The error message thrown by the processor. Supports <<accessing-template-fields,template snippets>>.
  1246. include::ingest-node-common-processor.asciidoc[]
  1247. |======
  1248. [source,js]
  1249. --------------------------------------------------
  1250. {
  1251. "fail": {
  1252. "if" : "ctx.tags.contains('production') != true",
  1253. "message": "The production tag is not present, found tags: {{tags}}"
  1254. }
  1255. }
  1256. --------------------------------------------------
  1257. // NOTCONSOLE
  1258. [[foreach-processor]]
  1259. === Foreach Processor
  1260. Processes elements in an array of unknown length.
  1261. All processors can operate on elements inside an array, but if all elements of an array need to
  1262. be processed in the same way, defining a processor for each element becomes cumbersome and tricky
  1263. because it is likely that the number of elements in an array is unknown. For this reason the `foreach`
  1264. processor exists. By specifying the field holding array elements and a processor that
  1265. defines what should happen to each element, array fields can easily be preprocessed.
  1266. A processor inside the foreach processor works in the array element context and puts that in the ingest metadata
  1267. under the `_ingest._value` key. If the array element is a json object it holds all immediate fields of that json object.
  1268. and if the nested object is a value is `_ingest._value` just holds that value. Note that if a processor prior to the
  1269. `foreach` processor used `_ingest._value` key then the specified value will not be available to the processor inside
  1270. the `foreach` processor. The `foreach` processor does restore the original value, so that value is available to processors
  1271. after the `foreach` processor.
  1272. Note that any other field from the document are accessible and modifiable like with all other processors. This processor
  1273. just puts the current array element being read into `_ingest._value` ingest metadata attribute, so that it may be
  1274. pre-processed.
  1275. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified,
  1276. then it aborts the execution and leaves the array unmodified.
  1277. [[foreach-options]]
  1278. .Foreach Options
  1279. [options="header"]
  1280. |======
  1281. | Name | Required | Default | Description
  1282. | `field` | yes | - | The array field
  1283. | `processor` | yes | - | The processor to execute against each field
  1284. | `ignore_missing` | no | false | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1285. include::ingest-node-common-processor.asciidoc[]
  1286. |======
  1287. Assume the following document:
  1288. [source,js]
  1289. --------------------------------------------------
  1290. {
  1291. "values" : ["foo", "bar", "baz"]
  1292. }
  1293. --------------------------------------------------
  1294. // NOTCONSOLE
  1295. When this `foreach` processor operates on this sample document:
  1296. [source,js]
  1297. --------------------------------------------------
  1298. {
  1299. "foreach" : {
  1300. "field" : "values",
  1301. "processor" : {
  1302. "uppercase" : {
  1303. "field" : "_ingest._value"
  1304. }
  1305. }
  1306. }
  1307. }
  1308. --------------------------------------------------
  1309. // NOTCONSOLE
  1310. Then the document will look like this after preprocessing:
  1311. [source,js]
  1312. --------------------------------------------------
  1313. {
  1314. "values" : ["FOO", "BAR", "BAZ"]
  1315. }
  1316. --------------------------------------------------
  1317. // NOTCONSOLE
  1318. Let's take a look at another example:
  1319. [source,js]
  1320. --------------------------------------------------
  1321. {
  1322. "persons" : [
  1323. {
  1324. "id" : "1",
  1325. "name" : "John Doe"
  1326. },
  1327. {
  1328. "id" : "2",
  1329. "name" : "Jane Doe"
  1330. }
  1331. ]
  1332. }
  1333. --------------------------------------------------
  1334. // NOTCONSOLE
  1335. In this case, the `id` field needs to be removed,
  1336. so the following `foreach` processor is used:
  1337. [source,js]
  1338. --------------------------------------------------
  1339. {
  1340. "foreach" : {
  1341. "field" : "persons",
  1342. "processor" : {
  1343. "remove" : {
  1344. "field" : "_ingest._value.id"
  1345. }
  1346. }
  1347. }
  1348. }
  1349. --------------------------------------------------
  1350. // NOTCONSOLE
  1351. After preprocessing the result is:
  1352. [source,js]
  1353. --------------------------------------------------
  1354. {
  1355. "persons" : [
  1356. {
  1357. "name" : "John Doe"
  1358. },
  1359. {
  1360. "name" : "Jane Doe"
  1361. }
  1362. ]
  1363. }
  1364. --------------------------------------------------
  1365. // NOTCONSOLE
  1366. The wrapped processor can have a `on_failure` definition.
  1367. For example, the `id` field may not exist on all person objects.
  1368. Instead of failing the index request, you can use an `on_failure`
  1369. block to send the document to the 'failure_index' index for later inspection:
  1370. [source,js]
  1371. --------------------------------------------------
  1372. {
  1373. "foreach" : {
  1374. "field" : "persons",
  1375. "processor" : {
  1376. "remove" : {
  1377. "field" : "_value.id",
  1378. "on_failure" : [
  1379. {
  1380. "set" : {
  1381. "field", "_index",
  1382. "value", "failure_index"
  1383. }
  1384. }
  1385. ]
  1386. }
  1387. }
  1388. }
  1389. }
  1390. --------------------------------------------------
  1391. // NOTCONSOLE
  1392. In this example, if the `remove` processor does fail, then
  1393. the array elements that have been processed thus far will
  1394. be updated.
  1395. Another advanced example can be found in the {plugins}/ingest-attachment-with-arrays.html[attachment processor documentation].
  1396. [[grok-processor]]
  1397. === Grok Processor
  1398. Extracts structured fields out of a single text field within a document. You choose which field to
  1399. extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular
  1400. expression that supports aliased expressions that can be reused.
  1401. This tool is perfect for syslog logs, apache and other webserver logs, mysql logs, and in general, any log format
  1402. that is generally written for humans and not computer consumption.
  1403. This processor comes packaged with many
  1404. https://github.com/elastic/elasticsearch/blob/{branch}/libs/grok/src/main/resources/patterns[reusable patterns].
  1405. 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.
  1406. [[grok-basics]]
  1407. ==== Grok Basics
  1408. Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
  1409. The regular expression library is Oniguruma, and you can see the full supported regexp syntax
  1410. https://github.com/kkos/oniguruma/blob/master/doc/RE[on the Onigiruma site].
  1411. Grok works by leveraging this regular expression language to allow naming existing patterns and combining them into more
  1412. complex patterns that match your fields.
  1413. The syntax for reusing a grok pattern comes in three forms: `%{SYNTAX:SEMANTIC}`, `%{SYNTAX}`, `%{SYNTAX:SEMANTIC:TYPE}`.
  1414. The `SYNTAX` is the name of the pattern that will match your text. For example, `3.44` will be matched by the `NUMBER`
  1415. pattern and `55.3.244.1` will be matched by the `IP` pattern. The syntax is how you match. `NUMBER` and `IP` are both
  1416. patterns that are provided within the default patterns set.
  1417. The `SEMANTIC` is the identifier you give to the piece of text being matched. For example, `3.44` could be the
  1418. duration of an event, so you could call it simply `duration`. Further, a string `55.3.244.1` might identify
  1419. the `client` making a request.
  1420. The `TYPE` is the type you wish to cast your named field. `int`, `long`, `double`, `float` and `boolean` are supported types for coercion.
  1421. For example, you might want to match the following text:
  1422. [source,txt]
  1423. --------------------------------------------------
  1424. 3.44 55.3.244.1
  1425. --------------------------------------------------
  1426. 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
  1427. Grok expression.
  1428. [source,txt]
  1429. --------------------------------------------------
  1430. %{NUMBER:duration} %{IP:client}
  1431. --------------------------------------------------
  1432. [[using-grok]]
  1433. ==== Using the Grok Processor in a Pipeline
  1434. [[grok-options]]
  1435. .Grok Options
  1436. [options="header"]
  1437. |======
  1438. | Name | Required | Default | Description
  1439. | `field` | yes | - | The field to use for grok expression parsing
  1440. | `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.
  1441. | `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.
  1442. | `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.
  1443. | `ignore_missing` | no | false | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1444. include::ingest-node-common-processor.asciidoc[]
  1445. |======
  1446. Here is an example of using the provided patterns to extract out and name structured fields from a string field in
  1447. a document.
  1448. [source,js]
  1449. --------------------------------------------------
  1450. {
  1451. "message": "55.3.244.1 GET /index.html 15824 0.043"
  1452. }
  1453. --------------------------------------------------
  1454. // NOTCONSOLE
  1455. The pattern for this could be:
  1456. [source,txt]
  1457. --------------------------------------------------
  1458. %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}
  1459. --------------------------------------------------
  1460. Here is an example pipeline for processing the above document by using Grok:
  1461. [source,js]
  1462. --------------------------------------------------
  1463. {
  1464. "description" : "...",
  1465. "processors": [
  1466. {
  1467. "grok": {
  1468. "field": "message",
  1469. "patterns": ["%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"]
  1470. }
  1471. }
  1472. ]
  1473. }
  1474. --------------------------------------------------
  1475. // NOTCONSOLE
  1476. This pipeline will insert these named captures as new fields within the document, like so:
  1477. [source,js]
  1478. --------------------------------------------------
  1479. {
  1480. "message": "55.3.244.1 GET /index.html 15824 0.043",
  1481. "client": "55.3.244.1",
  1482. "method": "GET",
  1483. "request": "/index.html",
  1484. "bytes": 15824,
  1485. "duration": "0.043"
  1486. }
  1487. --------------------------------------------------
  1488. // NOTCONSOLE
  1489. [[custom-patterns]]
  1490. ==== Custom Patterns
  1491. The Grok processor comes pre-packaged with a base set of pattern. These patterns may not always have
  1492. what you are looking for. Pattern have a very basic format. Each entry describes has a name and the pattern itself.
  1493. You can add your own patterns to a processor definition under the `pattern_definitions` option.
  1494. Here is an example of a pipeline specifying custom pattern definitions:
  1495. [source,js]
  1496. --------------------------------------------------
  1497. {
  1498. "description" : "...",
  1499. "processors": [
  1500. {
  1501. "grok": {
  1502. "field": "message",
  1503. "patterns": ["my %{FAVORITE_DOG:dog} is colored %{RGB:color}"],
  1504. "pattern_definitions" : {
  1505. "FAVORITE_DOG" : "beagle",
  1506. "RGB" : "RED|GREEN|BLUE"
  1507. }
  1508. }
  1509. }
  1510. ]
  1511. }
  1512. --------------------------------------------------
  1513. // NOTCONSOLE
  1514. [[trace-match]]
  1515. ==== Providing Multiple Match Patterns
  1516. Sometimes one pattern is not enough to capture the potential structure of a field. Let's assume we
  1517. want to match all messages that contain your favorite pet breeds of either cats or dogs. One way to accomplish
  1518. this is to provide two distinct patterns that can be matched, instead of one really complicated expression capturing
  1519. the same `or` behavior.
  1520. Here is an example of such a configuration executed against the simulate API:
  1521. [source,js]
  1522. --------------------------------------------------
  1523. POST _ingest/pipeline/_simulate
  1524. {
  1525. "pipeline": {
  1526. "description" : "parse multiple patterns",
  1527. "processors": [
  1528. {
  1529. "grok": {
  1530. "field": "message",
  1531. "patterns": ["%{FAVORITE_DOG:pet}", "%{FAVORITE_CAT:pet}"],
  1532. "pattern_definitions" : {
  1533. "FAVORITE_DOG" : "beagle",
  1534. "FAVORITE_CAT" : "burmese"
  1535. }
  1536. }
  1537. }
  1538. ]
  1539. },
  1540. "docs":[
  1541. {
  1542. "_source": {
  1543. "message": "I love burmese cats!"
  1544. }
  1545. }
  1546. ]
  1547. }
  1548. --------------------------------------------------
  1549. // CONSOLE
  1550. response:
  1551. [source,js]
  1552. --------------------------------------------------
  1553. {
  1554. "docs": [
  1555. {
  1556. "doc": {
  1557. "_type": "_type",
  1558. "_index": "_index",
  1559. "_id": "_id",
  1560. "_source": {
  1561. "message": "I love burmese cats!",
  1562. "pet": "burmese"
  1563. },
  1564. "_ingest": {
  1565. "timestamp": "2016-11-08T19:43:03.850+0000"
  1566. }
  1567. }
  1568. }
  1569. ]
  1570. }
  1571. --------------------------------------------------
  1572. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  1573. Both patterns will set the field `pet` with the appropriate match, but what if we want to trace which of our
  1574. patterns matched and populated our fields? We can do this with the `trace_match` parameter. Here is the output of
  1575. that same pipeline, but with `"trace_match": true` configured:
  1576. ////
  1577. Hidden setup for example:
  1578. [source,js]
  1579. --------------------------------------------------
  1580. POST _ingest/pipeline/_simulate
  1581. {
  1582. "pipeline": {
  1583. "description" : "parse multiple patterns",
  1584. "processors": [
  1585. {
  1586. "grok": {
  1587. "field": "message",
  1588. "patterns": ["%{FAVORITE_DOG:pet}", "%{FAVORITE_CAT:pet}"],
  1589. "trace_match": true,
  1590. "pattern_definitions" : {
  1591. "FAVORITE_DOG" : "beagle",
  1592. "FAVORITE_CAT" : "burmese"
  1593. }
  1594. }
  1595. }
  1596. ]
  1597. },
  1598. "docs":[
  1599. {
  1600. "_source": {
  1601. "message": "I love burmese cats!"
  1602. }
  1603. }
  1604. ]
  1605. }
  1606. --------------------------------------------------
  1607. // CONSOLE
  1608. ////
  1609. [source,js]
  1610. --------------------------------------------------
  1611. {
  1612. "docs": [
  1613. {
  1614. "doc": {
  1615. "_type": "_type",
  1616. "_index": "_index",
  1617. "_id": "_id",
  1618. "_source": {
  1619. "message": "I love burmese cats!",
  1620. "pet": "burmese"
  1621. },
  1622. "_ingest": {
  1623. "_grok_match_index": "1",
  1624. "timestamp": "2016-11-08T19:43:03.850+0000"
  1625. }
  1626. }
  1627. }
  1628. ]
  1629. }
  1630. --------------------------------------------------
  1631. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  1632. 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
  1633. second (index starts at zero) pattern in `patterns` to match.
  1634. This trace metadata enables debugging which of the patterns matched. This information is stored in the ingest
  1635. metadata and will not be indexed.
  1636. [[grok-processor-rest-get]]
  1637. ==== Retrieving patterns from REST endpoint
  1638. The Grok Processor comes packaged with its own REST endpoint for retrieving which patterns the processor is packaged with.
  1639. [source,js]
  1640. --------------------------------------------------
  1641. GET _ingest/processor/grok
  1642. --------------------------------------------------
  1643. // CONSOLE
  1644. The above request will return a response body containing a key-value representation of the built-in patterns dictionary.
  1645. [source,js]
  1646. --------------------------------------------------
  1647. {
  1648. "patterns" : {
  1649. "BACULA_CAPACITY" : "%{INT}{1,3}(,%{INT}{3})*",
  1650. "PATH" : "(?:%{UNIXPATH}|%{WINPATH})",
  1651. ...
  1652. }
  1653. --------------------------------------------------
  1654. // NOTCONSOLE
  1655. This can be useful to reference as the built-in patterns change across versions.
  1656. [[grok-watchdog]]
  1657. ==== Grok watchdog
  1658. Grok expressions that take too long to execute are interrupted and
  1659. the grok processor then fails with an exception. The grok
  1660. processor has a watchdog thread that determines when evaluation of
  1661. a grok expression takes too long and is controlled by the following
  1662. settings:
  1663. [[grok-watchdog-options]]
  1664. .Grok watchdog settings
  1665. [options="header"]
  1666. |======
  1667. | Name | Default | Description
  1668. | `ingest.grok.watchdog.interval` | 1s | How often to check whether there are grok evaluations that take longer than the maximum allowed execution time.
  1669. | `ingest.grok.watchdog.max_execution_time` | 1s | The maximum allowed execution of a grok expression evaluation.
  1670. |======
  1671. [[gsub-processor]]
  1672. === Gsub Processor
  1673. Converts a string field by applying a regular expression and a replacement.
  1674. If the field is not a string, the processor will throw an exception.
  1675. [[gsub-options]]
  1676. .Gsub Options
  1677. [options="header"]
  1678. |======
  1679. | Name | Required | Default | Description
  1680. | `field` | yes | - | The field to apply the replacement to
  1681. | `pattern` | yes | - | The pattern to be replaced
  1682. | `replacement` | yes | - | The string to replace the matching patterns with
  1683. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1684. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1685. include::ingest-node-common-processor.asciidoc[]
  1686. |======
  1687. [source,js]
  1688. --------------------------------------------------
  1689. {
  1690. "gsub": {
  1691. "field": "field1",
  1692. "pattern": "\.",
  1693. "replacement": "-"
  1694. }
  1695. }
  1696. --------------------------------------------------
  1697. // NOTCONSOLE
  1698. [[join-processor]]
  1699. === Join Processor
  1700. Joins each element of an array into a single string using a separator character between each element.
  1701. Throws an error when the field is not an array.
  1702. [[join-options]]
  1703. .Join Options
  1704. [options="header"]
  1705. |======
  1706. | Name | Required | Default | Description
  1707. | `field` | yes | - | The field to be separated
  1708. | `separator` | yes | - | The separator character
  1709. | `target_field` | no | `field` | The field to assign the joined value to, by default `field` is updated in-place
  1710. include::ingest-node-common-processor.asciidoc[]
  1711. |======
  1712. [source,js]
  1713. --------------------------------------------------
  1714. {
  1715. "join": {
  1716. "field": "joined_array_field",
  1717. "separator": "-"
  1718. }
  1719. }
  1720. --------------------------------------------------
  1721. // NOTCONSOLE
  1722. [[json-processor]]
  1723. === JSON Processor
  1724. Converts a JSON string into a structured JSON object.
  1725. [[json-options]]
  1726. .Json Options
  1727. [options="header"]
  1728. |======
  1729. | Name | Required | Default | Description
  1730. | `field` | yes | - | The field to be parsed
  1731. | `target_field` | no | `field` | The field to insert the converted structured object into
  1732. | `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.
  1733. include::ingest-node-common-processor.asciidoc[]
  1734. |======
  1735. All JSON-supported types will be parsed (null, boolean, number, array, object, string).
  1736. Suppose you provide this configuration of the `json` processor:
  1737. [source,js]
  1738. --------------------------------------------------
  1739. {
  1740. "json" : {
  1741. "field" : "string_source",
  1742. "target_field" : "json_target"
  1743. }
  1744. }
  1745. --------------------------------------------------
  1746. // NOTCONSOLE
  1747. If the following document is processed:
  1748. [source,js]
  1749. --------------------------------------------------
  1750. {
  1751. "string_source": "{\"foo\": 2000}"
  1752. }
  1753. --------------------------------------------------
  1754. // NOTCONSOLE
  1755. after the `json` processor operates on it, it will look like:
  1756. [source,js]
  1757. --------------------------------------------------
  1758. {
  1759. "string_source": "{\"foo\": 2000}",
  1760. "json_target": {
  1761. "foo": 2000
  1762. }
  1763. }
  1764. --------------------------------------------------
  1765. // NOTCONSOLE
  1766. If the following configuration is provided, omitting the optional `target_field` setting:
  1767. [source,js]
  1768. --------------------------------------------------
  1769. {
  1770. "json" : {
  1771. "field" : "source_and_target"
  1772. }
  1773. }
  1774. --------------------------------------------------
  1775. // NOTCONSOLE
  1776. then after the `json` processor operates on this document:
  1777. [source,js]
  1778. --------------------------------------------------
  1779. {
  1780. "source_and_target": "{\"foo\": 2000}"
  1781. }
  1782. --------------------------------------------------
  1783. // NOTCONSOLE
  1784. it will look like:
  1785. [source,js]
  1786. --------------------------------------------------
  1787. {
  1788. "source_and_target": {
  1789. "foo": 2000
  1790. }
  1791. }
  1792. --------------------------------------------------
  1793. // NOTCONSOLE
  1794. This illustrates that, unless it is explicitly named in the processor configuration, the `target_field`
  1795. is the same field provided in the required `field` configuration.
  1796. [[kv-processor]]
  1797. === KV Processor
  1798. This processor helps automatically parse messages (or specific event fields) which are of the foo=bar variety.
  1799. For example, if you have a log message which contains `ip=1.2.3.4 error=REFUSED`, you can parse those automatically by configuring:
  1800. [source,js]
  1801. --------------------------------------------------
  1802. {
  1803. "kv": {
  1804. "field": "message",
  1805. "field_split": " ",
  1806. "value_split": "="
  1807. }
  1808. }
  1809. --------------------------------------------------
  1810. // NOTCONSOLE
  1811. [[kv-options]]
  1812. .Kv Options
  1813. [options="header"]
  1814. |======
  1815. | Name | Required | Default | Description
  1816. | `field` | yes | - | The field to be parsed
  1817. | `field_split` | yes | - | Regex pattern to use for splitting key-value pairs
  1818. | `value_split` | yes | - | Regex pattern to use for splitting the key from the value within a key-value pair
  1819. | `target_field` | no | `null` | The field to insert the extracted keys into. Defaults to the root of the document
  1820. | `include_keys` | no | `null` | List of keys to filter and insert into document. Defaults to including all keys
  1821. | `exclude_keys` | no | `null` | List of keys to exclude from document
  1822. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1823. | `prefix` | no | `null` | Prefix to be added to extracted keys
  1824. | `trim_key` | no | `null` | String of characters to trim from extracted keys
  1825. | `trim_value` | no | `null` | String of characters to trim from extracted values
  1826. | `strip_brackets` | no | `false` | If `true` strip brackets `()`, `<>`, `[]` as well as quotes `'` and `"` from extracted values
  1827. include::ingest-node-common-processor.asciidoc[]
  1828. |======
  1829. [[lowercase-processor]]
  1830. === Lowercase Processor
  1831. Converts a string to its lowercase equivalent.
  1832. [[lowercase-options]]
  1833. .Lowercase Options
  1834. [options="header"]
  1835. |======
  1836. | Name | Required | Default | Description
  1837. | `field` | yes | - | The field to make lowercase
  1838. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  1839. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1840. include::ingest-node-common-processor.asciidoc[]
  1841. |======
  1842. [source,js]
  1843. --------------------------------------------------
  1844. {
  1845. "lowercase": {
  1846. "field": "foo"
  1847. }
  1848. }
  1849. --------------------------------------------------
  1850. // NOTCONSOLE
  1851. [[pipeline-processor]]
  1852. === Pipeline Processor
  1853. Executes another pipeline.
  1854. [[pipeline-options]]
  1855. .Pipeline Options
  1856. [options="header"]
  1857. |======
  1858. | Name | Required | Default | Description
  1859. | `name` | yes | - | The name of the pipeline to execute
  1860. include::ingest-node-common-processor.asciidoc[]
  1861. |======
  1862. [source,js]
  1863. --------------------------------------------------
  1864. {
  1865. "pipeline": {
  1866. "name": "inner-pipeline"
  1867. }
  1868. }
  1869. --------------------------------------------------
  1870. // NOTCONSOLE
  1871. An example of using this processor for nesting pipelines would be:
  1872. Define an inner pipeline:
  1873. [source,js]
  1874. --------------------------------------------------
  1875. PUT _ingest/pipeline/pipelineA
  1876. {
  1877. "description" : "inner pipeline",
  1878. "processors" : [
  1879. {
  1880. "set" : {
  1881. "field": "inner_pipeline_set",
  1882. "value": "inner"
  1883. }
  1884. }
  1885. ]
  1886. }
  1887. --------------------------------------------------
  1888. // CONSOLE
  1889. Define another pipeline that uses the previously defined inner pipeline:
  1890. [source,js]
  1891. --------------------------------------------------
  1892. PUT _ingest/pipeline/pipelineB
  1893. {
  1894. "description" : "outer pipeline",
  1895. "processors" : [
  1896. {
  1897. "pipeline" : {
  1898. "name": "pipelineA"
  1899. }
  1900. },
  1901. {
  1902. "set" : {
  1903. "field": "outer_pipeline_set",
  1904. "value": "outer"
  1905. }
  1906. }
  1907. ]
  1908. }
  1909. --------------------------------------------------
  1910. // CONSOLE
  1911. // TEST[continued]
  1912. Now indexing a document while applying the outer pipeline will see the inner pipeline executed
  1913. from the outer pipeline:
  1914. [source,js]
  1915. --------------------------------------------------
  1916. PUT /myindex/_doc/1?pipeline=pipelineB
  1917. {
  1918. "field": "value"
  1919. }
  1920. --------------------------------------------------
  1921. // CONSOLE
  1922. // TEST[continued]
  1923. Response from the index request:
  1924. [source,js]
  1925. --------------------------------------------------
  1926. {
  1927. "_index": "myindex",
  1928. "_type": "_doc",
  1929. "_id": "1",
  1930. "_version": 1,
  1931. "result": "created",
  1932. "_shards": {
  1933. "total": 2,
  1934. "successful": 1,
  1935. "failed": 0
  1936. },
  1937. "_seq_no": 0,
  1938. "_primary_term": 1,
  1939. }
  1940. --------------------------------------------------
  1941. // TESTRESPONSE
  1942. Indexed document:
  1943. [source,js]
  1944. --------------------------------------------------
  1945. {
  1946. "field": "value",
  1947. "inner_pipeline_set": "inner",
  1948. "outer_pipeline_set": "outer"
  1949. }
  1950. --------------------------------------------------
  1951. // NOTCONSOLE
  1952. [[remove-processor]]
  1953. === Remove Processor
  1954. Removes existing fields. If one field doesn't exist, an exception will be thrown.
  1955. [[remove-options]]
  1956. .Remove Options
  1957. [options="header"]
  1958. |======
  1959. | Name | Required | Default | Description
  1960. | `field` | yes | - | Fields to be removed. Supports <<accessing-template-fields,template snippets>>.
  1961. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  1962. include::ingest-node-common-processor.asciidoc[]
  1963. |======
  1964. Here is an example to remove a single field:
  1965. [source,js]
  1966. --------------------------------------------------
  1967. {
  1968. "remove": {
  1969. "field": "user_agent"
  1970. }
  1971. }
  1972. --------------------------------------------------
  1973. // NOTCONSOLE
  1974. To remove multiple fields, you can use the following query:
  1975. [source,js]
  1976. --------------------------------------------------
  1977. {
  1978. "remove": {
  1979. "field": ["user_agent", "url"]
  1980. }
  1981. }
  1982. --------------------------------------------------
  1983. // NOTCONSOLE
  1984. [[rename-processor]]
  1985. === Rename Processor
  1986. Renames an existing field. If the field doesn't exist or the new name is already used, an exception will be thrown.
  1987. [[rename-options]]
  1988. .Rename Options
  1989. [options="header"]
  1990. |======
  1991. | Name | Required | Default | Description
  1992. | `field` | yes | - | The field to be renamed. Supports <<accessing-template-fields,template snippets>>.
  1993. | `target_field` | yes | - | The new name of the field. Supports <<accessing-template-fields,template snippets>>.
  1994. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  1995. include::ingest-node-common-processor.asciidoc[]
  1996. |======
  1997. [source,js]
  1998. --------------------------------------------------
  1999. {
  2000. "rename": {
  2001. "field": "provider",
  2002. "target_field": "cloud.provider"
  2003. }
  2004. }
  2005. --------------------------------------------------
  2006. // NOTCONSOLE
  2007. [[script-processor]]
  2008. === Script Processor
  2009. Allows inline and stored scripts to be executed within ingest pipelines.
  2010. See <<modules-scripting-using, How to use scripts>> to learn more about writing scripts. The Script Processor
  2011. leverages caching of compiled scripts for improved performance. Since the
  2012. script specified within the processor is potentially re-compiled per document, it is important
  2013. to understand how script caching works. To learn more about
  2014. caching see <<modules-scripting-using-caching, Script Caching>>.
  2015. [[script-options]]
  2016. .Script Options
  2017. [options="header"]
  2018. |======
  2019. | Name | Required | Default | Description
  2020. | `lang` | no | "painless" | The scripting language
  2021. | `id` | no | - | The stored script id to refer to
  2022. | `source` | no | - | An inline script to be executed
  2023. | `params` | no | - | Script Parameters
  2024. include::ingest-node-common-processor.asciidoc[]
  2025. |======
  2026. One of `id` or `source` options must be provided in order to properly reference a script to execute.
  2027. You can access the current ingest document from within the script context by using the `ctx` variable.
  2028. The following example sets a new field called `field_a_plus_b_times_c` to be the sum of two existing
  2029. numeric fields `field_a` and `field_b` multiplied by the parameter param_c:
  2030. [source,js]
  2031. --------------------------------------------------
  2032. {
  2033. "script": {
  2034. "lang": "painless",
  2035. "source": "ctx.field_a_plus_b_times_c = (ctx.field_a + ctx.field_b) * params.param_c",
  2036. "params": {
  2037. "param_c": 10
  2038. }
  2039. }
  2040. }
  2041. --------------------------------------------------
  2042. // NOTCONSOLE
  2043. It is possible to use the Script Processor to manipulate document metadata like `_index` and `_type` during
  2044. ingestion. Here is an example of an Ingest Pipeline that renames the index and type to `my_index` no matter what
  2045. was provided in the original index request:
  2046. [source,js]
  2047. --------------------------------------------------
  2048. PUT _ingest/pipeline/my_index
  2049. {
  2050. "description": "use index:my_index and type:_doc",
  2051. "processors": [
  2052. {
  2053. "script": {
  2054. "source": """
  2055. ctx._index = 'my_index';
  2056. ctx._type = '_doc';
  2057. """
  2058. }
  2059. }
  2060. ]
  2061. }
  2062. --------------------------------------------------
  2063. // CONSOLE
  2064. Using the above pipeline, we can attempt to index a document into the `any_index` index.
  2065. [source,js]
  2066. --------------------------------------------------
  2067. PUT any_index/_doc/1?pipeline=my_index
  2068. {
  2069. "message": "text"
  2070. }
  2071. --------------------------------------------------
  2072. // CONSOLE
  2073. // TEST[continued]
  2074. The response from the above index request:
  2075. [source,js]
  2076. --------------------------------------------------
  2077. {
  2078. "_index": "my_index",
  2079. "_type": "_doc",
  2080. "_id": "1",
  2081. "_version": 1,
  2082. "result": "created",
  2083. "_shards": {
  2084. "total": 2,
  2085. "successful": 1,
  2086. "failed": 0
  2087. },
  2088. "_seq_no": 0,
  2089. "_primary_term": 1,
  2090. }
  2091. --------------------------------------------------
  2092. // TESTRESPONSE
  2093. In the above response, you can see that our document was actually indexed into `my_index` instead of
  2094. `any_index`. This type of manipulation is often convenient in pipelines that have various branches of transformation,
  2095. and depending on the progress made, indexed into different indices.
  2096. [[set-processor]]
  2097. === Set Processor
  2098. Sets one field and associates it with the specified value. If the field already exists,
  2099. its value will be replaced with the provided one.
  2100. [[set-options]]
  2101. .Set Options
  2102. [options="header"]
  2103. |======
  2104. | Name | Required | Default | Description
  2105. | `field` | yes | - | The field to insert, upsert, or update. Supports <<accessing-template-fields,template snippets>>.
  2106. | `value` | yes | - | The value to be set for the field. Supports <<accessing-template-fields,template snippets>>.
  2107. | `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.
  2108. include::ingest-node-common-processor.asciidoc[]
  2109. |======
  2110. [source,js]
  2111. --------------------------------------------------
  2112. {
  2113. "set": {
  2114. "field": "host.os.name",
  2115. "value": "{{os}}"
  2116. }
  2117. }
  2118. --------------------------------------------------
  2119. // NOTCONSOLE
  2120. [[ingest-node-set-security-user-processor]]
  2121. === Set Security User Processor
  2122. Sets user-related details (such as `username`, `roles`, `email`, `full_name`
  2123. and `metadata` ) from the current
  2124. authenticated user to the current document by pre-processing the ingest.
  2125. IMPORTANT: Requires an authenticated user for the index request.
  2126. [[set-security-user-options]]
  2127. .Set Security User Options
  2128. [options="header"]
  2129. |======
  2130. | Name | Required | Default | Description
  2131. | `field` | yes | - | The field to store the user information into.
  2132. | `properties` | no | [`username`, `roles`, `email`, `full_name`, `metadata`] | Controls what user related properties are added to the `field`.
  2133. include::ingest-node-common-processor.asciidoc[]
  2134. |======
  2135. The following example adds all user details for the current authenticated user
  2136. to the `user` field for all documents that are processed by this pipeline:
  2137. [source,js]
  2138. --------------------------------------------------
  2139. {
  2140. "processors" : [
  2141. {
  2142. "set_security_user": {
  2143. "field": "user"
  2144. }
  2145. }
  2146. ]
  2147. }
  2148. --------------------------------------------------
  2149. // NOTCONSOLE
  2150. [[split-processor]]
  2151. === Split Processor
  2152. Splits a field into an array using a separator character. Only works on string fields.
  2153. [[split-options]]
  2154. .Split Options
  2155. [options="header"]
  2156. |======
  2157. | Name | Required | Default | Description
  2158. | `field` | yes | - | The field to split
  2159. | `separator` | yes | - | A regex which matches the separator, eg `,` or `\s+`
  2160. | `target_field` | no | `field` | The field to assign the split value to, by default `field` is updated in-place
  2161. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  2162. include::ingest-node-common-processor.asciidoc[]
  2163. |======
  2164. [source,js]
  2165. --------------------------------------------------
  2166. {
  2167. "split": {
  2168. "field": "my_field",
  2169. "separator": "\\s+" <1>
  2170. }
  2171. }
  2172. --------------------------------------------------
  2173. // NOTCONSOLE
  2174. <1> Treat all consecutive whitespace characters as a single separator
  2175. [[sort-processor]]
  2176. === Sort Processor
  2177. Sorts the elements of an array ascending or descending. Homogeneous arrays of numbers will be sorted
  2178. numerically, while arrays of strings or heterogeneous arrays of strings + numbers will be sorted lexicographically.
  2179. Throws an error when the field is not an array.
  2180. [[sort-options]]
  2181. .Sort Options
  2182. [options="header"]
  2183. |======
  2184. | Name | Required | Default | Description
  2185. | `field` | yes | - | The field to be sorted
  2186. | `order` | no | `"asc"` | The sort order to use. Accepts `"asc"` or `"desc"`.
  2187. | `target_field` | no | `field` | The field to assign the sorted value to, by default `field` is updated in-place
  2188. include::ingest-node-common-processor.asciidoc[]
  2189. |======
  2190. [source,js]
  2191. --------------------------------------------------
  2192. {
  2193. "sort": {
  2194. "field": "array_field_to_sort",
  2195. "order": "desc"
  2196. }
  2197. }
  2198. --------------------------------------------------
  2199. // NOTCONSOLE
  2200. [[trim-processor]]
  2201. === Trim Processor
  2202. Trims whitespace from field.
  2203. NOTE: This only works on leading and trailing whitespace.
  2204. [[trim-options]]
  2205. .Trim Options
  2206. [options="header"]
  2207. |======
  2208. | Name | Required | Default | Description
  2209. | `field` | yes | - | The string-valued field to trim whitespace from
  2210. | `target_field` | no | `field` | The field to assign the trimmed value to, by default `field` is updated in-place
  2211. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  2212. include::ingest-node-common-processor.asciidoc[]
  2213. |======
  2214. [source,js]
  2215. --------------------------------------------------
  2216. {
  2217. "trim": {
  2218. "field": "foo"
  2219. }
  2220. }
  2221. --------------------------------------------------
  2222. // NOTCONSOLE
  2223. [[uppercase-processor]]
  2224. === Uppercase Processor
  2225. Converts a string to its uppercase equivalent.
  2226. [[uppercase-options]]
  2227. .Uppercase Options
  2228. [options="header"]
  2229. |======
  2230. | Name | Required | Default | Description
  2231. | `field` | yes | - | The field to make uppercase
  2232. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  2233. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  2234. include::ingest-node-common-processor.asciidoc[]
  2235. |======
  2236. [source,js]
  2237. --------------------------------------------------
  2238. {
  2239. "uppercase": {
  2240. "field": "foo"
  2241. }
  2242. }
  2243. --------------------------------------------------
  2244. // NOTCONSOLE
  2245. [[urldecode-processor]]
  2246. === URL Decode Processor
  2247. URL-decodes a string
  2248. [[urldecode-options]]
  2249. .URL Decode Options
  2250. [options="header"]
  2251. |======
  2252. | Name | Required | Default | Description
  2253. | `field` | yes | - | The field to decode
  2254. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  2255. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  2256. include::ingest-node-common-processor.asciidoc[]
  2257. |======
  2258. [source,js]
  2259. --------------------------------------------------
  2260. {
  2261. "urldecode": {
  2262. "field": "my_url_to_decode"
  2263. }
  2264. }
  2265. --------------------------------------------------
  2266. // NOTCONSOLE