ingest-node.asciidoc 41 KB

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