ingest-node.asciidoc 76 KB

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