ingest-node.asciidoc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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. "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. The <<ingest-stats,node stats API>> can be used to fetch ingest usage statistics, globally and on a per
  559. pipeline basis. Useful to find out which pipelines are used the most or spent the most time on preprocessing.
  560. [[append-procesesor]]
  561. === Append Processor
  562. Appends one or more values to an existing array if the field already exists and it is an array.
  563. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar.
  564. Creates an array containing the provided values if the field doesn't exist.
  565. Accepts a single value or an array of values.
  566. [[append-options]]
  567. .Append Options
  568. [options="header"]
  569. |======
  570. | Name | Required | Default | Description
  571. | `field` | yes | - | The field to be appended to
  572. | `value` | yes | - | The value to be appended
  573. |======
  574. [source,js]
  575. --------------------------------------------------
  576. {
  577. "append": {
  578. "field": "field1"
  579. "value": ["item2", "item3", "item4"]
  580. }
  581. }
  582. --------------------------------------------------
  583. [[convert-processor]]
  584. === Convert Processor
  585. Converts an existing field's value to a different type, such as converting a string to an integer.
  586. If the field value is an array, all members will be converted.
  587. The supported types include: `integer`, `float`, `string`, `boolean`, and `auto`.
  588. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  589. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  590. Specifying `auto` will attempt to convert the string-valued `field` into the closest non-string type.
  591. For example, a field whose value is `"true"` will be converted to its respective boolean type: `true`. And
  592. a value of `"242.15"` will "automatically" be converted to `242.15` of type `float`. If a provided field cannot
  593. be appropriately converted, the Convert Processor will still process successfully and leave the field value as-is. In
  594. such a case, `target_field` will still be updated with the unconverted field value.
  595. [[convert-options]]
  596. .Convert Options
  597. [options="header"]
  598. |======
  599. | Name | Required | Default | Description
  600. | `field` | yes | - | The field whose value is to be converted
  601. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  602. | `type` | yes | - | The type to convert the existing value to
  603. |======
  604. [source,js]
  605. --------------------------------------------------
  606. {
  607. "convert": {
  608. "field" : "foo"
  609. "type": "integer"
  610. }
  611. }
  612. --------------------------------------------------
  613. [[date-processor]]
  614. === Date Processor
  615. Parses dates from fields, and then uses the date or timestamp as the timestamp for the document.
  616. By default, the date processor adds the parsed date as a new field called `@timestamp`. You can specify a
  617. different field by setting the `target_field` configuration parameter. Multiple date formats are supported
  618. as part of the same date processor definition. They will be used sequentially to attempt parsing the date field,
  619. in the same order they were defined as part of the processor definition.
  620. [[date-options]]
  621. .Date options
  622. [options="header"]
  623. |======
  624. | Name | Required | Default | Description
  625. | `match_field` | yes | - | The field to get the date from.
  626. | `target_field` | no | @timestamp | The field that will hold the parsed date.
  627. | `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.
  628. | `timezone` | no | UTC | The timezone to use when parsing the date.
  629. | `locale` | no | ENGLISH | The locale to use when parsing the date, relevant when parsing month names or week days.
  630. |======
  631. Here is an example that adds the parsed date to the `timestamp` field based on the `initial_date` field:
  632. [source,js]
  633. --------------------------------------------------
  634. {
  635. "description" : "...",
  636. "processors" : [
  637. {
  638. "date" : {
  639. "match_field" : "initial_date",
  640. "target_field" : "timestamp",
  641. "match_formats" : ["dd/MM/yyyy hh:mm:ss"],
  642. "timezone" : "Europe/Amsterdam"
  643. }
  644. }
  645. ]
  646. }
  647. --------------------------------------------------
  648. [[fail-processor]]
  649. === Fail Processor
  650. Raises an exception. This is useful for when
  651. you expect a pipeline to fail and want to relay a specific message
  652. to the requester.
  653. [[fail-options]]
  654. .Fail Options
  655. [options="header"]
  656. |======
  657. | Name | Required | Default | Description
  658. | `message` | yes | - | The error message of the `FailException` thrown by the processor
  659. |======
  660. [source,js]
  661. --------------------------------------------------
  662. {
  663. "fail": {
  664. "message": "an error message"
  665. }
  666. }
  667. --------------------------------------------------
  668. [[foreach-processor]]
  669. === Foreach Processor
  670. Processes elements in an array of unknown length.
  671. All processors can operate on elements inside an array, but if all elements of an array need to
  672. be processed in the same way, defining a processor for each element becomes cumbersome and tricky
  673. because it is likely that the number of elements in an array is unknown. For this reason the `foreach`
  674. processor exists. By specifying the field holding array elements and a list of processors that
  675. define what should happen to each element, array fields can easily be preprocessed.
  676. Processors inside the foreach processor work in a different context, and the only valid top-level
  677. field is `_value`, which holds the array element value. Under this field other fields may exist.
  678. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified,
  679. then it aborts the execution and leaves the array unmodified.
  680. [[foreach-options]]
  681. .Foreach Options
  682. [options="header"]
  683. |======
  684. | Name | Required | Default | Description
  685. | `field` | yes | - | The array field
  686. | `processors` | yes | - | The processors
  687. |======
  688. Assume the following document:
  689. [source,js]
  690. --------------------------------------------------
  691. {
  692. "value" : ["foo", "bar", "baz"]
  693. }
  694. --------------------------------------------------
  695. When this `foreach` processor operates on this sample document:
  696. [source,js]
  697. --------------------------------------------------
  698. {
  699. "foreach" : {
  700. "field" : "values",
  701. "processors" : [
  702. {
  703. "uppercase" : {
  704. "field" : "_value"
  705. }
  706. }
  707. ]
  708. }
  709. }
  710. --------------------------------------------------
  711. Then the document will look like this after preprocessing:
  712. [source,js]
  713. --------------------------------------------------
  714. {
  715. "value" : ["FOO", "BAR", "BAZ"]
  716. }
  717. --------------------------------------------------
  718. Let's take a look at another example:
  719. [source,js]
  720. --------------------------------------------------
  721. {
  722. "persons" : [
  723. {
  724. "id" : "1",
  725. "name" : "John Doe"
  726. },
  727. {
  728. "id" : "2",
  729. "name" : "Jane Doe"
  730. }
  731. ]
  732. }
  733. --------------------------------------------------
  734. In this case, the `id` field needs to be removed,
  735. so the following `foreach` processor is used:
  736. [source,js]
  737. --------------------------------------------------
  738. {
  739. "foreach" : {
  740. "field" : "persons",
  741. "processors" : [
  742. {
  743. "remove" : {
  744. "field" : "_value.id"
  745. }
  746. }
  747. ]
  748. }
  749. }
  750. --------------------------------------------------
  751. After preprocessing the result is:
  752. [source,js]
  753. --------------------------------------------------
  754. {
  755. "persons" : [
  756. {
  757. "name" : "John Doe"
  758. },
  759. {
  760. "name" : "Jane Doe"
  761. }
  762. ]
  763. }
  764. --------------------------------------------------
  765. As for any processor, you can define `on_failure` processors
  766. in processors that are wrapped inside the `foreach` processor.
  767. For example, the `id` field may not exist on all person objects.
  768. Instead of failing the index request, you can use an `on_failure`
  769. block to send the document to the 'failure_index' index for later inspection:
  770. [source,js]
  771. --------------------------------------------------
  772. {
  773. "foreach" : {
  774. "field" : "persons",
  775. "processors" : [
  776. {
  777. "remove" : {
  778. "field" : "_value.id",
  779. "on_failure" : [
  780. {
  781. "set" : {
  782. "field", "_index",
  783. "value", "failure_index"
  784. }
  785. }
  786. ]
  787. }
  788. }
  789. ]
  790. }
  791. }
  792. --------------------------------------------------
  793. In this example, if the `remove` processor does fail, then
  794. the array elements that have been processed thus far will
  795. be updated.
  796. [[grok-processor]]
  797. === Grok Processor
  798. Extracts structured fields out of a single text field within a document. You choose which field to
  799. extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular
  800. expression that supports aliased expressions that can be reused.
  801. This tool is perfect for syslog logs, apache and other webserver logs, mysql logs, and in general, any log format
  802. that is generally written for humans and not computer consumption.
  803. The processor comes packaged with over 120 reusable patterns that are located at `$ES_HOME/config/ingest/grok/patterns`.
  804. Here, you can add your own custom grok pattern files with custom grok expressions to be used by the processor.
  805. If you need help building patterns to match your logs, you will find the <http://grokdebug.herokuapp.com> and
  806. <http://grokconstructor.appspot.com/> applications quite useful!
  807. [[grok-basics]]
  808. ==== Grok Basics
  809. Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
  810. The regular expression library is Oniguruma, and you can see the full supported regexp syntax
  811. https://github.com/kkos/oniguruma/blob/master/doc/RE[on the Onigiruma site].
  812. Grok works by leveraging this regular expression language to allow naming existing patterns and combining them into more
  813. complex patterns that match your fields.
  814. The syntax for reusing a grok pattern comes in three forms: `%{SYNTAX:SEMANTIC}`, `%{SYNTAX}`, `%{SYNTAX:SEMANTIC:TYPE}`.
  815. The `SYNTAX` is the name of the pattern that will match your text. For example, `3.44` will be matched by the `NUMBER`
  816. pattern and `55.3.244.1` will be matched by the `IP` pattern. The syntax is how you match. `NUMBER` and `IP` are both
  817. patterns that are provided within the default patterns set.
  818. The `SEMANTIC` is the identifier you give to the piece of text being matched. For example, `3.44` could be the
  819. duration of an event, so you could call it simply `duration`. Further, a string `55.3.244.1` might identify
  820. the `client` making a request.
  821. The `TYPE` is the type you wish to cast your named field. `int` and `float` are currently the only types supported for coercion.
  822. For example, you might want to match the following text:
  823. [source,js]
  824. --------------------------------------------------
  825. 3.44 55.3.244.1
  826. --------------------------------------------------
  827. 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
  828. Grok expression.
  829. [source,js]
  830. --------------------------------------------------
  831. %{NUMBER:duration} %{IP:client}
  832. --------------------------------------------------
  833. [[using-grok]]
  834. ==== Using the Grok Processor in a Pipeline
  835. [[grok-options]]
  836. .Grok Options
  837. [options="header"]
  838. |======
  839. | Name | Required | Default | Description
  840. | `field` | yes | - | The field to use for grok expression parsing
  841. | `pattern` | yes | - | The grok expression to match and extract named captures with
  842. | `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.
  843. |======
  844. Here is an example of using the provided patterns to extract out and name structured fields from a string field in
  845. a document.
  846. [source,js]
  847. --------------------------------------------------
  848. {
  849. "message": "55.3.244.1 GET /index.html 15824 0.043"
  850. }
  851. --------------------------------------------------
  852. The pattern for this could be:
  853. [source,js]
  854. --------------------------------------------------
  855. %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}
  856. --------------------------------------------------
  857. Here is an example pipeline for processing the above document by using Grok:
  858. [source,js]
  859. --------------------------------------------------
  860. {
  861. "description" : "...",
  862. "processors": [
  863. {
  864. "grok": {
  865. "field": "message",
  866. "pattern": "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"
  867. }
  868. }
  869. ]
  870. }
  871. --------------------------------------------------
  872. This pipeline will insert these named captures as new fields within the document, like so:
  873. [source,js]
  874. --------------------------------------------------
  875. {
  876. "message": "55.3.244.1 GET /index.html 15824 0.043",
  877. "client": "55.3.244.1",
  878. "method": "GET",
  879. "request": "/index.html",
  880. "bytes": 15824,
  881. "duration": "0.043"
  882. }
  883. --------------------------------------------------
  884. [[custom-patterns]]
  885. ==== Custom Patterns and Pattern Files
  886. The Grok processor comes pre-packaged with a base set of pattern. These patterns may not always have
  887. what you are looking for. Pattern have a very basic format. Each entry describes has a name and the pattern itself.
  888. You can add your own patterns to a processor definition under the `pattern_definitions` option.
  889. Here is an example of a pipeline specifying custom pattern definitions:
  890. [source,js]
  891. --------------------------------------------------
  892. {
  893. "description" : "...",
  894. "processors": [
  895. {
  896. "grok": {
  897. "field": "message",
  898. "pattern": "my %{FAVORITE_DOG:dog} is colored %{RGB:color}"
  899. "pattern_definitions" : {
  900. "FAVORITE_DOG" : "beagle",
  901. "RGB" : "RED|GREEN|BLUE"
  902. }
  903. }
  904. }
  905. ]
  906. }
  907. --------------------------------------------------
  908. [[gsub-processor]]
  909. === Gsub Processor
  910. Converts a string field by applying a regular expression and a replacement.
  911. If the field is not a string, the processor will throw an exception.
  912. [[gsub-options]]
  913. .Gsub Options
  914. [options="header"]
  915. |======
  916. | Name | Required | Default | Description
  917. | `field` | yes | - | The field to apply the replacement to
  918. | `pattern` | yes | - | The pattern to be replaced
  919. | `replacement` | yes | - | The string to replace the matching patterns with
  920. |======
  921. [source,js]
  922. --------------------------------------------------
  923. {
  924. "gsub": {
  925. "field": "field1",
  926. "pattern": "\.",
  927. "replacement": "-"
  928. }
  929. }
  930. --------------------------------------------------
  931. [[join-processor]]
  932. === Join Processor
  933. Joins each element of an array into a single string using a separator character between each element.
  934. Throws an error when the field is not an array.
  935. [[join-options]]
  936. .Join Options
  937. [options="header"]
  938. |======
  939. | Name | Required | Default | Description
  940. | `field` | yes | - | The field to be separated
  941. | `separator` | yes | - | The separator character
  942. |======
  943. [source,js]
  944. --------------------------------------------------
  945. {
  946. "join": {
  947. "field": "joined_array_field",
  948. "separator": "-"
  949. }
  950. }
  951. --------------------------------------------------
  952. [[lowercase-processor]]
  953. === Lowercase Processor
  954. Converts a string to its lowercase equivalent.
  955. [[lowercase-options]]
  956. .Lowercase Options
  957. [options="header"]
  958. |======
  959. | Name | Required | Default | Description
  960. | `field` | yes | - | The field to make lowercase
  961. |======
  962. [source,js]
  963. --------------------------------------------------
  964. {
  965. "lowercase": {
  966. "field": "foo"
  967. }
  968. }
  969. --------------------------------------------------
  970. [[remove-processor]]
  971. === Remove Processor
  972. Removes an existing field. If the field doesn't exist, an exception will be thrown.
  973. [[remove-options]]
  974. .Remove Options
  975. [options="header"]
  976. |======
  977. | Name | Required | Default | Description
  978. | `field` | yes | - | The field to be removed
  979. |======
  980. [source,js]
  981. --------------------------------------------------
  982. {
  983. "remove": {
  984. "field": "foo"
  985. }
  986. }
  987. --------------------------------------------------
  988. [[rename-processor]]
  989. === Rename Processor
  990. Renames an existing field. If the field doesn't exist or the new name is already used, an exception will be thrown.
  991. [[rename-options]]
  992. .Rename Options
  993. [options="header"]
  994. |======
  995. | Name | Required | Default | Description
  996. | `field` | yes | - | The field to be renamed
  997. | `to` | yes | - | The new name of the field
  998. |======
  999. [source,js]
  1000. --------------------------------------------------
  1001. {
  1002. "rename": {
  1003. "field": "foo",
  1004. "to": "foobar"
  1005. }
  1006. }
  1007. --------------------------------------------------
  1008. [[set-processor]]
  1009. === Set Processor
  1010. Sets one field and associates it with the specified value. If the field already exists,
  1011. its value will be replaced with the provided one.
  1012. [[set-options]]
  1013. .Set Options
  1014. [options="header"]
  1015. |======
  1016. | Name | Required | Default | Description
  1017. | `field` | yes | - | The field to insert, upsert, or update
  1018. | `value` | yes | - | The value to be set for the field
  1019. |======
  1020. [source,js]
  1021. --------------------------------------------------
  1022. {
  1023. "set": {
  1024. "field": "field1",
  1025. "value": 582.1
  1026. }
  1027. }
  1028. --------------------------------------------------
  1029. [[split-processor]]
  1030. === Split Processor
  1031. Splits a field into an array using a separator character. Only works on string fields.
  1032. [[split-options]]
  1033. .Split Options
  1034. [options="header"]
  1035. |======
  1036. | Name | Required | Default | Description
  1037. | `field` | yes | - | The field to split
  1038. |======
  1039. [source,js]
  1040. --------------------------------------------------
  1041. {
  1042. "split": {
  1043. "field": ","
  1044. }
  1045. }
  1046. --------------------------------------------------
  1047. [[trim-processor]]
  1048. === Trim Processor
  1049. Trims whitespace from field.
  1050. NOTE: This only works on leading and trailing whitespace.
  1051. [[trim-options]]
  1052. .Trim Options
  1053. [options="header"]
  1054. |======
  1055. | Name | Required | Default | Description
  1056. | `field` | yes | - | The string-valued field to trim whitespace from
  1057. |======
  1058. [source,js]
  1059. --------------------------------------------------
  1060. {
  1061. "trim": {
  1062. "field": "foo"
  1063. }
  1064. }
  1065. --------------------------------------------------
  1066. [[uppercase-processor]]
  1067. === Uppercase Processor
  1068. Converts a string to its uppercase equivalent.
  1069. [[uppercase-options]]
  1070. .Uppercase Options
  1071. [options="header"]
  1072. |======
  1073. | Name | Required | Default | Description
  1074. | `field` | yes | - | The field to make uppercase
  1075. |======
  1076. [source,js]
  1077. --------------------------------------------------
  1078. {
  1079. "uppercase": {
  1080. "field": "foo"
  1081. }
  1082. }
  1083. --------------------------------------------------