ingest-node.asciidoc 58 KB

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