ingest-node.asciidoc 81 KB

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