ingest-node.asciidoc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. [[pipe-line]]
  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. "simple" : {
  35. // settings
  36. }
  37. },
  38. // other processors
  39. ]
  40. }
  41. --------------------------------------------------
  42. // AUTOSENSE
  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. // AUTOSENSE
  53. Example response:
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "my-pipeline-id": {
  58. "_source" : {
  59. "description": "describe pipeline",
  60. "processors": [
  61. {
  62. "simple" : {
  63. // settings
  64. }
  65. },
  66. // other processors
  67. ]
  68. },
  69. "_version" : 0
  70. }
  71. }
  72. --------------------------------------------------
  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. [[delete-pipeline-api]]
  77. === Delete Pipeline API
  78. The delete pipeline API deletes pipelines by ID.
  79. [source,js]
  80. --------------------------------------------------
  81. DELETE _ingest/pipeline/my-pipeline-id
  82. --------------------------------------------------
  83. // AUTOSENSE
  84. [[simulate-pipeline-api]]
  85. === Simulate Pipeline API
  86. The simulate pipeline API executes a specific pipeline against
  87. the set of documents provided in the body of the request.
  88. You can either specify an existing pipeline to execute
  89. against the provided documents, or supply a pipeline definition in
  90. the body of the request.
  91. Here is the structure of a simulate request with a pipeline definition provided
  92. in the body of the request:
  93. [source,js]
  94. --------------------------------------------------
  95. POST _ingest/pipeline/_simulate
  96. {
  97. "pipeline" : {
  98. // pipeline definition here
  99. },
  100. "docs" : [
  101. { /** first document **/ },
  102. { /** second document **/ },
  103. // ...
  104. ]
  105. }
  106. --------------------------------------------------
  107. Here is the structure of a simulate request against an existing pipeline:
  108. [source,js]
  109. --------------------------------------------------
  110. POST _ingest/pipeline/my-pipeline-id/_simulate
  111. {
  112. "docs" : [
  113. { /** first document **/ },
  114. { /** second document **/ },
  115. // ...
  116. ]
  117. }
  118. --------------------------------------------------
  119. Here is an example of a simulate request with a pipeline defined in the request
  120. and its response:
  121. [source,js]
  122. --------------------------------------------------
  123. POST _ingest/pipeline/_simulate
  124. {
  125. "pipeline" :
  126. {
  127. "description": "_description",
  128. "processors": [
  129. {
  130. "set" : {
  131. "field" : "field2",
  132. "value" : "_value"
  133. }
  134. }
  135. ]
  136. },
  137. "docs": [
  138. {
  139. "_index": "index",
  140. "_type": "type",
  141. "_id": "id",
  142. "_source": {
  143. "foo": "bar"
  144. }
  145. },
  146. {
  147. "_index": "index",
  148. "_type": "type",
  149. "_id": "id",
  150. "_source": {
  151. "foo": "rab"
  152. }
  153. }
  154. ]
  155. }
  156. --------------------------------------------------
  157. // AUTOSENSE
  158. Response:
  159. [source,js]
  160. --------------------------------------------------
  161. {
  162. "docs": [
  163. {
  164. "doc": {
  165. "_id": "id",
  166. "_ttl": null,
  167. "_parent": null,
  168. "_index": "index",
  169. "_routing": null,
  170. "_type": "type",
  171. "_timestamp": null,
  172. "_source": {
  173. "field2": "_value",
  174. "foo": "bar"
  175. },
  176. "_ingest": {
  177. "timestamp": "2016-01-04T23:53:27.186+0000"
  178. }
  179. }
  180. },
  181. {
  182. "doc": {
  183. "_id": "id",
  184. "_ttl": null,
  185. "_parent": null,
  186. "_index": "index",
  187. "_routing": null,
  188. "_type": "type",
  189. "_timestamp": null,
  190. "_source": {
  191. "field2": "_value",
  192. "foo": "rab"
  193. },
  194. "_ingest": {
  195. "timestamp": "2016-01-04T23:53:27.186+0000"
  196. }
  197. }
  198. }
  199. ]
  200. }
  201. --------------------------------------------------
  202. [[ingest-verbose-param]]
  203. ==== Viewing Verbose Results
  204. You can use the simulate pipeline API to see how each processor affects the ingest document
  205. as it passes through the pipeline. To see the intermediate results of
  206. each processor in the simulate request, you can add the `verbose` parameter
  207. to the request.
  208. Here is an example of a verbose request and its response:
  209. [source,js]
  210. --------------------------------------------------
  211. POST _ingest/pipeline/_simulate?verbose
  212. {
  213. "pipeline" :
  214. {
  215. "description": "_description",
  216. "processors": [
  217. {
  218. "set" : {
  219. "field" : "field2",
  220. "value" : "_value2"
  221. }
  222. },
  223. {
  224. "set" : {
  225. "field" : "field3",
  226. "value" : "_value3"
  227. }
  228. }
  229. ]
  230. },
  231. "docs": [
  232. {
  233. "_index": "index",
  234. "_type": "type",
  235. "_id": "id",
  236. "_source": {
  237. "foo": "bar"
  238. }
  239. },
  240. {
  241. "_index": "index",
  242. "_type": "type",
  243. "_id": "id",
  244. "_source": {
  245. "foo": "rab"
  246. }
  247. }
  248. ]
  249. }
  250. --------------------------------------------------
  251. // AUTOSENSE
  252. Response:
  253. [source,js]
  254. --------------------------------------------------
  255. {
  256. "docs": [
  257. {
  258. "processor_results": [
  259. {
  260. "tag": "processor[set]-0",
  261. "doc": {
  262. "_id": "id",
  263. "_ttl": null,
  264. "_parent": null,
  265. "_index": "index",
  266. "_routing": null,
  267. "_type": "type",
  268. "_timestamp": null,
  269. "_source": {
  270. "field2": "_value2",
  271. "foo": "bar"
  272. },
  273. "_ingest": {
  274. "timestamp": "2016-01-05T00:02:51.383+0000"
  275. }
  276. }
  277. },
  278. {
  279. "tag": "processor[set]-1",
  280. "doc": {
  281. "_id": "id",
  282. "_ttl": null,
  283. "_parent": null,
  284. "_index": "index",
  285. "_routing": null,
  286. "_type": "type",
  287. "_timestamp": null,
  288. "_source": {
  289. "field3": "_value3",
  290. "field2": "_value2",
  291. "foo": "bar"
  292. },
  293. "_ingest": {
  294. "timestamp": "2016-01-05T00:02:51.383+0000"
  295. }
  296. }
  297. }
  298. ]
  299. },
  300. {
  301. "processor_results": [
  302. {
  303. "tag": "processor[set]-0",
  304. "doc": {
  305. "_id": "id",
  306. "_ttl": null,
  307. "_parent": null,
  308. "_index": "index",
  309. "_routing": null,
  310. "_type": "type",
  311. "_timestamp": null,
  312. "_source": {
  313. "field2": "_value2",
  314. "foo": "rab"
  315. },
  316. "_ingest": {
  317. "timestamp": "2016-01-05T00:02:51.384+0000"
  318. }
  319. }
  320. },
  321. {
  322. "tag": "processor[set]-1",
  323. "doc": {
  324. "_id": "id",
  325. "_ttl": null,
  326. "_parent": null,
  327. "_index": "index",
  328. "_routing": null,
  329. "_type": "type",
  330. "_timestamp": null,
  331. "_source": {
  332. "field3": "_value3",
  333. "field2": "_value2",
  334. "foo": "rab"
  335. },
  336. "_ingest": {
  337. "timestamp": "2016-01-05T00:02:51.384+0000"
  338. }
  339. }
  340. }
  341. ]
  342. }
  343. ]
  344. }
  345. --------------------------------------------------
  346. [[accessing-data-in-pipelines]]
  347. == Accessing Data in Pipelines
  348. The processors in a pipeline have read and write access to documents that pass through the pipeline.
  349. The processors can access fields in the source of a document and the document's metadata fields.
  350. [float]
  351. [[accessing-source-fields]]
  352. === Accessing Fields in the Source
  353. Accessing a field in the source is straightforward. You simply refer to fields by
  354. their name. For example:
  355. [source,js]
  356. --------------------------------------------------
  357. {
  358. "set": {
  359. "field": "my_field"
  360. "value": 582.1
  361. }
  362. }
  363. --------------------------------------------------
  364. On top of this, fields from the source are always accessible via the `_source` prefix:
  365. [source,js]
  366. --------------------------------------------------
  367. {
  368. "set": {
  369. "field": "_source.my_field"
  370. "value": 582.1
  371. }
  372. }
  373. --------------------------------------------------
  374. [float]
  375. [[accessing-metadata-fields]]
  376. === Accessing Metadata Fields
  377. You can access metadata fields in the same way that you access fields in the source. This
  378. is possible because Elasticsearch doesn't allow fields in the source that have the
  379. same name as metadata fields.
  380. The following example sets the `_id` metadata field of a document to `1`:
  381. [source,js]
  382. --------------------------------------------------
  383. {
  384. "set": {
  385. "field": "_id"
  386. "value": "1"
  387. }
  388. }
  389. --------------------------------------------------
  390. The following metadata fields are accessible by a processor: `_index`, `_type`, `_id`, `_routing`, `_parent`,
  391. `_timestamp`, and `_ttl`.
  392. [float]
  393. [[accessing-ingest-metadata]]
  394. === Accessing Ingest Metadata Fields
  395. Beyond metadata fields and source fields, ingest also adds ingest metadata to the documents that it processes.
  396. These metadata properties are accessible under the `_ingest` key. Currently ingest adds the ingest timestamp
  397. under the `_ingest.timestamp` key of the ingest metadata. The ingest timestamp is the time when Elasticsearch
  398. received the index or bulk request to pre-process the document.
  399. Any processor can add ingest-related metadata during document processing. Ingest metadata is transient
  400. and is lost after a document has been processed by the pipeline. Therefore, ingest metadata won't be indexed.
  401. The following example adds a field with the name `received`. The value is the ingest timestamp:
  402. [source,js]
  403. --------------------------------------------------
  404. {
  405. "set": {
  406. "field": "received"
  407. "value": "{{_ingest.timestamp}}"
  408. }
  409. }
  410. --------------------------------------------------
  411. Unlike Elasticsearch metadata fields, the ingest metadata field name `_ingest` can be used as a valid field name
  412. in the source of a document. Use `_source._ingest` to refer to the field in the source document. Otherwise, `_ingest`
  413. will be interpreted as an ingest metadata field.
  414. [float]
  415. [[accessing-template-fields]]
  416. === Accessing Fields and Metafields in Templates
  417. A number of processor settings also support templating. Settings that support templating can have zero or more
  418. template snippets. A template snippet begins with `{{` and ends with `}}`.
  419. Accessing fields and metafields in templates is exactly the same as via regular processor field settings.
  420. The following example adds a field named `field_c`. Its value is a concatenation of
  421. the values of `field_a` and `field_b`.
  422. [source,js]
  423. --------------------------------------------------
  424. {
  425. "set": {
  426. "field": "field_c"
  427. "value": "{{field_a}} {{field_b}}"
  428. }
  429. }
  430. --------------------------------------------------
  431. The following example uses the value of the `geoip.country_iso_code` field in the source
  432. to set the index that the document will be indexed into:
  433. [source,js]
  434. --------------------------------------------------
  435. {
  436. "set": {
  437. "field": "_index"
  438. "value": "{{geoip.country_iso_code}}"
  439. }
  440. }
  441. --------------------------------------------------
  442. [[handling-failure-in-pipelines]]
  443. == Handling Failures in Pipelines
  444. In its simplest use case, a pipeline defines a list of processors that
  445. are executed sequentially, and processing halts at the first exception. This
  446. behavior may not be desirable when failures are expected. For example, you may have logs
  447. that don't match the specified grok expression. Instead of halting execution, you may
  448. want to index such documents into a separate index.
  449. To enable this behavior, you can use the `on_failure` parameter. The `on_failure` parameter
  450. defines a list of processors to be executed immediately following the failed processor.
  451. You can specify this parameter at the pipeline level, as well as at the processor
  452. level. If a processor specifies an `on_failure` configuration, whether
  453. it is empty or not, any exceptions that are thrown by the processor are caught, and the
  454. pipeline continues executing the remaining processors. Because you can define further processors
  455. within the scope of an `on_failure` statement, you can nest failure handling.
  456. The following example defines a pipeline that renames the `foo` field in
  457. the processed document to `bar`. If the document does not contain the `foo` field, the processor
  458. attaches an error message to the document for later analysis within
  459. Elasticsearch.
  460. [source,js]
  461. --------------------------------------------------
  462. {
  463. "description" : "my first pipeline with handled exceptions",
  464. "processors" : [
  465. {
  466. "rename" : {
  467. "field" : "foo",
  468. "to" : "bar",
  469. "on_failure" : [
  470. {
  471. "set" : {
  472. "field" : "error",
  473. "value" : "field \"foo\" does not exist, cannot rename to \"bar\""
  474. }
  475. }
  476. ]
  477. }
  478. }
  479. ]
  480. }
  481. --------------------------------------------------
  482. The following example defines an `on_failure` block on a whole pipeline to change
  483. the index to which failed documents get sent.
  484. [source,js]
  485. --------------------------------------------------
  486. {
  487. "description" : "my first pipeline with handled exceptions",
  488. "processors" : [ ... ],
  489. "on_failure" : [
  490. {
  491. "set" : {
  492. "field" : "_index",
  493. "value" : "failed-{{ _index }}"
  494. }
  495. }
  496. ]
  497. }
  498. --------------------------------------------------
  499. [float]
  500. [[accessing-error-metadata]]
  501. === Accessing Error Metadata From Processors Handling Exceptions
  502. You may want to retrieve the actual error message that was thrown
  503. by a failed processor. To do so you can access metadata fields called
  504. `on_failure_message`, `on_failure_processor_type`, and `on_failure_processor_tag`. These fields are only accessible
  505. from within the context of an `on_failure` block.
  506. Here is an updated version of the example that you
  507. saw earlier. But instead of setting the error message manually, the example leverages the `on_failure_message`
  508. metadata field to provide the error message.
  509. [source,js]
  510. --------------------------------------------------
  511. {
  512. "description" : "my first pipeline with handled exceptions",
  513. "processors" : [
  514. {
  515. "rename" : {
  516. "field" : "foo",
  517. "to" : "bar",
  518. "on_failure" : [
  519. {
  520. "set" : {
  521. "field" : "error",
  522. "value" : "{{ _ingest.on_failure_message }}"
  523. }
  524. }
  525. ]
  526. }
  527. }
  528. ]
  529. }
  530. --------------------------------------------------
  531. [[ingest-processors]]
  532. == Processors
  533. All processors are defined in the following way within a pipeline definition:
  534. [source,js]
  535. --------------------------------------------------
  536. {
  537. "PROCESSOR_NAME" : {
  538. ... processor configuration options ...
  539. }
  540. }
  541. --------------------------------------------------
  542. Each processor defines its own configuration parameters, but all processors have
  543. the ability to declare `tag` and `on_failure` fields. These fields are optional.
  544. A `tag` is simply a string identifier of the specific instantiation of a certain
  545. processor in a pipeline. The `tag` field does not affect the processor's behavior,
  546. but is very useful for bookkeeping and tracing errors to specific processors.
  547. See <<handling-failure-in-pipelines>> to learn more about the `on_failure` field and error handling in pipelines.
  548. The <<ingest-info,node info API>> can be used to figure out what processors are available in a cluster.
  549. The <<ingest-info,node info API>> will provide a per node list of what processors are available.
  550. Custom processors must be installed on all nodes. The put pipeline API will fail if a processor specified in a pipeline
  551. doesn't exist on all nodes. If you rely on custom processor plugins make sure to mark these plugins as mandatory by adding
  552. `plugin.mandatory` setting to the `config/elasticsearch.yml` file, for example:
  553. [source,yaml]
  554. --------------------------------------------------
  555. plugin.mandatory: ingest-attachment,ingest-geoip
  556. --------------------------------------------------
  557. A node will not start if either of these plugins are not available.
  558. [[append-procesesor]]
  559. === Append Processor
  560. Appends one or more values to an existing array if the field already exists and it is an array.
  561. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar.
  562. Creates an array containing the provided values if the field doesn't exist.
  563. Accepts a single value or an array of values.
  564. [[append-options]]
  565. .Append Options
  566. [options="header"]
  567. |======
  568. | Name | Required | Default | Description
  569. | `field` | yes | - | The field to be appended to
  570. | `value` | yes | - | The value to be appended
  571. |======
  572. [source,js]
  573. --------------------------------------------------
  574. {
  575. "append": {
  576. "field": "field1"
  577. "value": ["item2", "item3", "item4"]
  578. }
  579. }
  580. --------------------------------------------------
  581. [[convert-processor]]
  582. === Convert Processor
  583. Converts an existing field's value to a different type, such as converting a string to an integer.
  584. If the field value is an array, all members will be converted.
  585. The supported types include: `integer`, `float`, `string`, and `boolean`.
  586. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  587. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  588. [[convert-options]]
  589. .Convert Options
  590. [options="header"]
  591. |======
  592. | Name | Required | Default | Description
  593. | `field` | yes | - | The field whose value is to be converted
  594. | `type` | yes | - | The type to convert the existing value to
  595. |======
  596. [source,js]
  597. --------------------------------------------------
  598. {
  599. "convert": {
  600. "field" : "foo"
  601. "type": "integer"
  602. }
  603. }
  604. --------------------------------------------------
  605. [[date-processor]]
  606. === Date Processor
  607. Parses dates from fields, and then uses the date or timestamp as the timestamp for the document.
  608. By default, the date processor adds the parsed date as a new field called `@timestamp`. You can specify a
  609. different field by setting the `target_field` configuration parameter. Multiple date formats are supported
  610. as part of the same date processor definition. They will be used sequentially to attempt parsing the date field,
  611. in the same order they were defined as part of the processor definition.
  612. [[date-options]]
  613. .Date options
  614. [options="header"]
  615. |======
  616. | Name | Required | Default | Description
  617. | `match_field` | yes | - | The field to get the date from.
  618. | `target_field` | no | @timestamp | The field that will hold the parsed date.
  619. | `match_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.
  620. | `timezone` | no | UTC | The timezone to use when parsing the date.
  621. | `locale` | no | ENGLISH | The locale to use when parsing the date, relevant when parsing month names or week days.
  622. |======
  623. Here is an example that adds the parsed date to the `timestamp` field based on the `initial_date` field:
  624. [source,js]
  625. --------------------------------------------------
  626. {
  627. "description" : "...",
  628. "processors" : [
  629. {
  630. "date" : {
  631. "match_field" : "initial_date",
  632. "target_field" : "timestamp",
  633. "match_formats" : ["dd/MM/yyyy hh:mm:ss"],
  634. "timezone" : "Europe/Amsterdam"
  635. }
  636. }
  637. ]
  638. }
  639. --------------------------------------------------
  640. [[fail-processor]]
  641. === Fail Processor
  642. Raises an exception. This is useful for when
  643. you expect a pipeline to fail and want to relay a specific message
  644. to the requester.
  645. [[fail-options]]
  646. .Fail Options
  647. [options="header"]
  648. |======
  649. | Name | Required | Default | Description
  650. | `message` | yes | - | The error message of the `FailException` thrown by the processor
  651. |======
  652. [source,js]
  653. --------------------------------------------------
  654. {
  655. "fail": {
  656. "message": "an error message"
  657. }
  658. }
  659. --------------------------------------------------
  660. [[foreach-processor]]
  661. === Foreach Processor
  662. Processes elements in an array of unknown length.
  663. All processors can operate on elements inside an array, but if all elements of an array need to
  664. be processed in the same way, defining a processor for each element becomes cumbersome and tricky
  665. because it is likely that the number of elements in an array is unknown. For this reason the `foreach`
  666. processor exists. By specifying the field holding array elements and a list of processors that
  667. define what should happen to each element, array fields can easily be preprocessed.
  668. Processors inside the foreach processor work in a different context, and the only valid top-level
  669. field is `_value`, which holds the array element value. Under this field other fields may exist.
  670. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified,
  671. then it aborts the execution and leaves the array unmodified.
  672. [[foreach-options]]
  673. .Foreach Options
  674. [options="header"]
  675. |======
  676. | Name | Required | Default | Description
  677. | `field` | yes | - | The array field
  678. | `processors` | yes | - | The processors
  679. |======
  680. Assume the following document:
  681. [source,js]
  682. --------------------------------------------------
  683. {
  684. "value" : ["foo", "bar", "baz"]
  685. }
  686. --------------------------------------------------
  687. When this `foreach` processor operates on this sample document:
  688. [source,js]
  689. --------------------------------------------------
  690. {
  691. "foreach" : {
  692. "field" : "values",
  693. "processors" : [
  694. {
  695. "uppercase" : {
  696. "field" : "_value"
  697. }
  698. }
  699. ]
  700. }
  701. }
  702. --------------------------------------------------
  703. Then the document will look like this after preprocessing:
  704. [source,js]
  705. --------------------------------------------------
  706. {
  707. "value" : ["FOO", "BAR", "BAZ"]
  708. }
  709. --------------------------------------------------
  710. Let's take a look at another example:
  711. [source,js]
  712. --------------------------------------------------
  713. {
  714. "persons" : [
  715. {
  716. "id" : "1",
  717. "name" : "John Doe"
  718. },
  719. {
  720. "id" : "2",
  721. "name" : "Jane Doe"
  722. }
  723. ]
  724. }
  725. --------------------------------------------------
  726. In this case, the `id` field needs to be removed,
  727. so the following `foreach` processor is used:
  728. [source,js]
  729. --------------------------------------------------
  730. {
  731. "foreach" : {
  732. "field" : "persons",
  733. "processors" : [
  734. {
  735. "remove" : {
  736. "field" : "_value.id"
  737. }
  738. }
  739. ]
  740. }
  741. }
  742. --------------------------------------------------
  743. After preprocessing the result is:
  744. [source,js]
  745. --------------------------------------------------
  746. {
  747. "persons" : [
  748. {
  749. "name" : "John Doe"
  750. },
  751. {
  752. "name" : "Jane Doe"
  753. }
  754. ]
  755. }
  756. --------------------------------------------------
  757. As for any processor, you can define `on_failure` processors
  758. in processors that are wrapped inside the `foreach` processor.
  759. For example, the `id` field may not exist on all person objects.
  760. Instead of failing the index request, you can use an `on_failure`
  761. block to send the document to the 'failure_index' index for later inspection:
  762. [source,js]
  763. --------------------------------------------------
  764. {
  765. "foreach" : {
  766. "field" : "persons",
  767. "processors" : [
  768. {
  769. "remove" : {
  770. "field" : "_value.id",
  771. "on_failure" : [
  772. {
  773. "set" : {
  774. "field", "_index",
  775. "value", "failure_index"
  776. }
  777. }
  778. ]
  779. }
  780. }
  781. ]
  782. }
  783. }
  784. --------------------------------------------------
  785. In this example, if the `remove` processor does fail, then
  786. the array elements that have been processed thus far will
  787. be updated.
  788. [[grok-processor]]
  789. === Grok Processor
  790. Extracts structured fields out of a single text field within a document. You choose which field to
  791. extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular
  792. expression that supports aliased expressions that can be reused.
  793. This tool is perfect for syslog logs, apache and other webserver logs, mysql logs, and in general, any log format
  794. that is generally written for humans and not computer consumption.
  795. The processor comes packaged with over 120 reusable patterns that are located at `$ES_HOME/config/ingest/grok/patterns`.
  796. Here, you can add your own custom grok pattern files with custom grok expressions to be used by the processor.
  797. If you need help building patterns to match your logs, you will find the <http://grokdebug.herokuapp.com> and
  798. <http://grokconstructor.appspot.com/> applications quite useful!
  799. [[grok-basics]]
  800. ==== Grok Basics
  801. Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
  802. The regular expression library is Oniguruma, and you can see the full supported regexp syntax
  803. https://github.com/kkos/oniguruma/blob/master/doc/RE[on the Onigiruma site].
  804. Grok works by leveraging this regular expression language to allow naming existing patterns and combining them into more
  805. complex patterns that match your fields.
  806. The syntax for reusing a grok pattern comes in three forms: `%{SYNTAX:SEMANTIC}`, `%{SYNTAX}`, `%{SYNTAX:SEMANTIC:TYPE}`.
  807. The `SYNTAX` is the name of the pattern that will match your text. For example, `3.44` will be matched by the `NUMBER`
  808. pattern and `55.3.244.1` will be matched by the `IP` pattern. The syntax is how you match. `NUMBER` and `IP` are both
  809. patterns that are provided within the default patterns set.
  810. The `SEMANTIC` is the identifier you give to the piece of text being matched. For example, `3.44` could be the
  811. duration of an event, so you could call it simply `duration`. Further, a string `55.3.244.1` might identify
  812. the `client` making a request.
  813. The `TYPE` is the type you wish to cast your named field. `int` and `float` are currently the only types supported for coercion.
  814. For example, you might want to match the following text:
  815. [source,js]
  816. --------------------------------------------------
  817. 3.44 55.3.244.1
  818. --------------------------------------------------
  819. 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
  820. Grok expression.
  821. [source,js]
  822. --------------------------------------------------
  823. %{NUMBER:duration} %{IP:client}
  824. --------------------------------------------------
  825. [[custom-patterns]]
  826. ==== Custom Patterns and Pattern Files
  827. The Grok processor comes pre-packaged with a base set of pattern files. These patterns may not always have
  828. what you are looking for. These pattern files have a very basic format. Each line describes a named pattern with
  829. the following format:
  830. [source,js]
  831. --------------------------------------------------
  832. NAME ' '+ PATTERN '\n'
  833. --------------------------------------------------
  834. You can add new patterns to an existing file, or add your own file in the patterns directory here: `$ES_HOME/config/ingest/grok/patterns`.
  835. Ingest node picks up files in this directory and loads the patterns into the grok processor's known patterns.
  836. These patterns are loaded at startup, so you need to restart your ingest node if you want to update these files.
  837. Here is an example snippet of pattern definitions found in the `grok-patterns` patterns file:
  838. [source,js]
  839. --------------------------------------------------
  840. YEAR (?>\d\d){1,2}
  841. HOUR (?:2[0123]|[01]?[0-9])
  842. MINUTE (?:[0-5][0-9])
  843. SECOND (?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?)
  844. TIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9])
  845. --------------------------------------------------
  846. [[using-grok]]
  847. ==== Using the Grok Processor in a Pipeline
  848. [[grok-options]]
  849. .Grok Options
  850. [options="header"]
  851. |======
  852. | Name | Required | Default | Description
  853. | `field` | yes | - | The field to use for grok expression parsing
  854. | `pattern` | yes | - | The grok expression to match and extract named captures with
  855. | `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.
  856. |======
  857. Here is an example of using the provided patterns to extract out and name structured fields from a string field in
  858. a document.
  859. [source,js]
  860. --------------------------------------------------
  861. {
  862. "message": "55.3.244.1 GET /index.html 15824 0.043"
  863. }
  864. --------------------------------------------------
  865. The pattern for this could be:
  866. [source,js]
  867. --------------------------------------------------
  868. %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}
  869. --------------------------------------------------
  870. Here is an example pipeline for processing the above document by using Grok:
  871. [source,js]
  872. --------------------------------------------------
  873. {
  874. "description" : "...",
  875. "processors": [
  876. {
  877. "grok": {
  878. "field": "message",
  879. "pattern": "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"
  880. }
  881. }
  882. ]
  883. }
  884. --------------------------------------------------
  885. This pipeline will insert these named captures as new fields within the document, like so:
  886. [source,js]
  887. --------------------------------------------------
  888. {
  889. "message": "55.3.244.1 GET /index.html 15824 0.043",
  890. "client": "55.3.244.1",
  891. "method": "GET",
  892. "request": "/index.html",
  893. "bytes": 15824,
  894. "duration": "0.043"
  895. }
  896. --------------------------------------------------
  897. Here is an example of a pipeline specifying custom pattern definitions:
  898. [source,js]
  899. --------------------------------------------------
  900. {
  901. "description" : "...",
  902. "processors": [
  903. {
  904. "grok": {
  905. "field": "message",
  906. "pattern": "my %{FAVORITE_DOG:dog} is colored %{RGB:color}"
  907. "pattern_definitions" : {
  908. "FAVORITE_DOG" : "beagle",
  909. "RGB" : "RED|GREEN|BLUE"
  910. }
  911. }
  912. }
  913. ]
  914. }
  915. --------------------------------------------------
  916. [[gsub-processor]]
  917. === Gsub Processor
  918. Converts a string field by applying a regular expression and a replacement.
  919. If the field is not a string, the processor will throw an exception.
  920. [[gsub-options]]
  921. .Gsub Options
  922. [options="header"]
  923. |======
  924. | Name | Required | Default | Description
  925. | `field` | yes | - | The field to apply the replacement to
  926. | `pattern` | yes | - | The pattern to be replaced
  927. | `replacement` | yes | - | The string to replace the matching patterns with
  928. |======
  929. [source,js]
  930. --------------------------------------------------
  931. {
  932. "gsub": {
  933. "field": "field1",
  934. "pattern": "\.",
  935. "replacement": "-"
  936. }
  937. }
  938. --------------------------------------------------
  939. [[join-processor]]
  940. === Join Processor
  941. Joins each element of an array into a single string using a separator character between each element.
  942. Throws an error when the field is not an array.
  943. [[join-options]]
  944. .Join Options
  945. [options="header"]
  946. |======
  947. | Name | Required | Default | Description
  948. | `field` | yes | - | The field to be separated
  949. | `separator` | yes | - | The separator character
  950. |======
  951. [source,js]
  952. --------------------------------------------------
  953. {
  954. "join": {
  955. "field": "joined_array_field",
  956. "separator": "-"
  957. }
  958. }
  959. --------------------------------------------------
  960. [[lowercase-processor]]
  961. === Lowercase Processor
  962. Converts a string to its lowercase equivalent.
  963. [[lowercase-options]]
  964. .Lowercase Options
  965. [options="header"]
  966. |======
  967. | Name | Required | Default | Description
  968. | `field` | yes | - | The field to make lowercase
  969. |======
  970. [source,js]
  971. --------------------------------------------------
  972. {
  973. "lowercase": {
  974. "field": "foo"
  975. }
  976. }
  977. --------------------------------------------------
  978. [[remove-processor]]
  979. === Remove Processor
  980. Removes an existing field. If the field doesn't exist, an exception will be thrown.
  981. [[remove-options]]
  982. .Remove Options
  983. [options="header"]
  984. |======
  985. | Name | Required | Default | Description
  986. | `field` | yes | - | The field to be removed
  987. |======
  988. [source,js]
  989. --------------------------------------------------
  990. {
  991. "remove": {
  992. "field": "foo"
  993. }
  994. }
  995. --------------------------------------------------
  996. [[rename-processor]]
  997. === Rename Processor
  998. Renames an existing field. If the field doesn't exist or the new name is already used, an exception will be thrown.
  999. [[rename-options]]
  1000. .Rename Options
  1001. [options="header"]
  1002. |======
  1003. | Name | Required | Default | Description
  1004. | `field` | yes | - | The field to be renamed
  1005. | `to` | yes | - | The new name of the field
  1006. |======
  1007. [source,js]
  1008. --------------------------------------------------
  1009. {
  1010. "rename": {
  1011. "field": "foo",
  1012. "to": "foobar"
  1013. }
  1014. }
  1015. --------------------------------------------------
  1016. [[set-processor]]
  1017. === Set Processor
  1018. Sets one field and associates it with the specified value. If the field already exists,
  1019. its value will be replaced with the provided one.
  1020. [[set-options]]
  1021. .Set Options
  1022. [options="header"]
  1023. |======
  1024. | Name | Required | Default | Description
  1025. | `field` | yes | - | The field to insert, upsert, or update
  1026. | `value` | yes | - | The value to be set for the field
  1027. |======
  1028. [source,js]
  1029. --------------------------------------------------
  1030. {
  1031. "set": {
  1032. "field": "field1",
  1033. "value": 582.1
  1034. }
  1035. }
  1036. --------------------------------------------------
  1037. [[split-processor]]
  1038. === Split Processor
  1039. Splits a field into an array using a separator character. Only works on string fields.
  1040. [[split-options]]
  1041. .Split Options
  1042. [options="header"]
  1043. |======
  1044. | Name | Required | Default | Description
  1045. | `field` | yes | - | The field to split
  1046. |======
  1047. [source,js]
  1048. --------------------------------------------------
  1049. {
  1050. "split": {
  1051. "field": ","
  1052. }
  1053. }
  1054. --------------------------------------------------
  1055. [[trim-processor]]
  1056. === Trim Processor
  1057. Trims whitespace from field.
  1058. NOTE: This only works on leading and trailing whitespace.
  1059. [[trim-options]]
  1060. .Trim Options
  1061. [options="header"]
  1062. |======
  1063. | Name | Required | Default | Description
  1064. | `field` | yes | - | The string-valued field to trim whitespace from
  1065. |======
  1066. [source,js]
  1067. --------------------------------------------------
  1068. {
  1069. "trim": {
  1070. "field": "foo"
  1071. }
  1072. }
  1073. --------------------------------------------------
  1074. [[uppercase-processor]]
  1075. === Uppercase Processor
  1076. Converts a string to its uppercase equivalent.
  1077. [[uppercase-options]]
  1078. .Uppercase Options
  1079. [options="header"]
  1080. |======
  1081. | Name | Required | Default | Description
  1082. | `field` | yes | - | The field to make uppercase
  1083. |======
  1084. [source,js]
  1085. --------------------------------------------------
  1086. {
  1087. "uppercase": {
  1088. "field": "foo"
  1089. }
  1090. }
  1091. --------------------------------------------------