dissect.asciidoc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. [[dissect-processor]]
  2. === Dissect processor
  3. ++++
  4. <titleabbrev>Dissect</titleabbrev>
  5. ++++
  6. Similar to the <<grok-processor,Grok Processor>>, dissect also extracts structured fields out of a single text field
  7. within a document. However unlike the <<grok-processor,Grok Processor>>, dissect does not use
  8. {wikipedia}/Regular_expression[Regular Expressions]. This allows dissect's syntax to be simple and for
  9. some cases faster than the <<grok-processor,Grok Processor>>.
  10. Dissect matches a single text field against a defined pattern.
  11. For example the following pattern:
  12. [source,txt]
  13. --------------------------------------------------
  14. %{clientip} %{ident} %{auth} [%{@timestamp}] \"%{verb} %{request} HTTP/%{httpversion}\" %{status} %{size}
  15. --------------------------------------------------
  16. will match a log line of this format:
  17. [source,txt]
  18. --------------------------------------------------
  19. 1.2.3.4 - - [30/Apr/1998:22:00:52 +0000] \"GET /english/venues/cities/images/montpellier/18.gif HTTP/1.0\" 200 3171
  20. --------------------------------------------------
  21. and result in a document with the following fields:
  22. [source,js]
  23. --------------------------------------------------
  24. "doc": {
  25. "_index": "_index",
  26. "_type": "_type",
  27. "_id": "_id",
  28. "_source": {
  29. "request": "/english/venues/cities/images/montpellier/18.gif",
  30. "auth": "-",
  31. "ident": "-",
  32. "verb": "GET",
  33. "@timestamp": "30/Apr/1998:22:00:52 +0000",
  34. "size": "3171",
  35. "clientip": "1.2.3.4",
  36. "httpversion": "1.0",
  37. "status": "200"
  38. }
  39. }
  40. --------------------------------------------------
  41. // NOTCONSOLE
  42. A dissect pattern is defined by the parts of the string that will be discarded. In the example above the first part
  43. to be discarded is a single space. Dissect finds this space, then assigns the value of `clientip` is everything up
  44. until that space.
  45. Later dissect matches the `[` and then `]` and then assigns `@timestamp` to everything in-between `[` and `]`.
  46. Paying special attention the parts of the string to discard will help build successful dissect patterns.
  47. Successful matches require all keys in a pattern to have a value. If any of the `%{keyname}` defined in the pattern do
  48. not have a value, then an exception is thrown and may be handled by the <<handling-failure-in-pipelines,on_failure>> directive.
  49. An empty key `%{}` or a <<dissect-modifier-named-skip-key, named skip key>> can be used to match values, but exclude the value from
  50. the final document. All matched values are represented as string data types. The <<convert-processor, convert processor>>
  51. may be used to convert to expected data type.
  52. Dissect also supports <<dissect-key-modifiers,key modifiers>> that can change dissect's default
  53. behavior. For example you can instruct dissect to ignore certain fields, append fields, skip over padding, etc.
  54. See <<dissect-key-modifiers, below>> for more information.
  55. [[dissect-options]]
  56. .Dissect Options
  57. [options="header"]
  58. |======
  59. | Name | Required | Default | Description
  60. | `field` | yes | - | The field to dissect
  61. | `pattern` | yes | - | The pattern to apply to the field
  62. | `append_separator`| no | "" (empty string) | The character(s) that separate the appended fields.
  63. | `ignore_missing` | no | false | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  64. include::common-options.asciidoc[]
  65. |======
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "dissect": {
  70. "field": "message",
  71. "pattern" : "%{clientip} %{ident} %{auth} [%{@timestamp}] \"%{verb} %{request} HTTP/%{httpversion}\" %{status} %{size}"
  72. }
  73. }
  74. --------------------------------------------------
  75. // NOTCONSOLE
  76. [[dissect-key-modifiers]]
  77. ==== Dissect key modifiers
  78. Key modifiers can change the default behavior for dissection. Key modifiers may be found on the left or right
  79. of the `%{keyname}` always inside the `%{` and `}`. For example `%{+keyname ->}` has the append and right padding
  80. modifiers.
  81. [[dissect-key-modifiers-table]]
  82. .Dissect Key Modifiers
  83. [options="header"]
  84. |======
  85. | Modifier | Name | Position | Example | Description | Details
  86. | `->` | Skip right padding | (far) right | `%{keyname1->}` | Skips any repeated characters to the right | <<dissect-modifier-skip-right-padding,link>>
  87. | `+` | Append | left | `%{+keyname} %{+keyname}` | Appends two or more fields together | <<dissect-modifier-append-key,link>>
  88. | `+` with `/n` | Append with order | left and right | `%{+keyname/2} %{+keyname/1}` | Appends two or more fields together in the order specified | <<dissect-modifier-append-key-with-order,link>>
  89. | `?` | Named skip key | left | `%{?ignoreme}` | Skips the matched value in the output. Same behavior as `%{}`| <<dissect-modifier-named-skip-key,link>>
  90. | `*` and `&` | Reference keys | left | `%{*r1} %{&r1}` | Sets the output key as value of `*` and output value of `&` | <<dissect-modifier-reference-keys,link>>
  91. |======
  92. [[dissect-modifier-skip-right-padding]]
  93. ===== Right padding modifier (`->`)
  94. The algorithm that performs the dissection is very strict in that it requires all characters in the pattern to match
  95. the source string. For example, the pattern `%{fookey} %{barkey}` (1 space), will match the string "foo{nbsp}bar"
  96. (1 space), but will not match the string "foo{nbsp}{nbsp}bar" (2 spaces) since the pattern has only 1 space and the
  97. source string has 2 spaces.
  98. The right padding modifier helps with this case. Adding the right padding modifier to the pattern `%{fookey->} %{barkey}`,
  99. It will now will match "foo{nbsp}bar" (1 space) and "foo{nbsp}{nbsp}bar" (2 spaces)
  100. and even "foo{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}bar" (10 spaces).
  101. Use the right padding modifier to allow for repetition of the characters after a `%{keyname->}`.
  102. The right padding modifier may be placed on any key with any other modifiers. It should always be the furthest right
  103. modifier. For example: `%{+keyname/1->}` and `%{->}`
  104. Right padding modifier example
  105. |======
  106. | *Pattern* | `%{ts->} %{level}`
  107. | *Input* | 1998-08-10T17:15:42,466{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}WARN
  108. | *Result* a|
  109. * ts = 1998-08-10T17:15:42,466
  110. * level = WARN
  111. |======
  112. The right padding modifier may be used with an empty key to help skip unwanted data. For example, the same input string, but wrapped with brackets requires the use of an empty right padded key to achieve the same result.
  113. Right padding modifier with empty key example
  114. |======
  115. | *Pattern* | `[%{ts}]%{->}[%{level}]`
  116. | *Input* | [1998-08-10T17:15:42,466]{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}{nbsp}[WARN]
  117. | *Result* a|
  118. * ts = 1998-08-10T17:15:42,466
  119. * level = WARN
  120. |======
  121. [[append-modifier]]
  122. ===== Append modifier (`+`)
  123. [[dissect-modifier-append-key]]
  124. Dissect supports appending two or more results together for the output.
  125. Values are appended left to right. An append separator can be specified.
  126. In this example the append_separator is defined as a space.
  127. Append modifier example
  128. |======
  129. | *Pattern* | `%{+name} %{+name} %{+name} %{+name}`
  130. | *Input* | john jacob jingleheimer schmidt
  131. | *Result* a|
  132. * name = john jacob jingleheimer schmidt
  133. |======
  134. [[append-order-modifier]]
  135. ===== Append with order modifier (`+` and `/n`)
  136. [[dissect-modifier-append-key-with-order]]
  137. Dissect supports appending two or more results together for the output.
  138. Values are appended based on the order defined (`/n`). An append separator can be specified.
  139. In this example the append_separator is defined as a comma.
  140. Append with order modifier example
  141. |======
  142. | *Pattern* | `%{+name/2} %{+name/4} %{+name/3} %{+name/1}`
  143. | *Input* | john jacob jingleheimer schmidt
  144. | *Result* a|
  145. * name = schmidt,john,jingleheimer,jacob
  146. |======
  147. [[named-skip-key]]
  148. ===== Named skip key (`?`)
  149. [[dissect-modifier-named-skip-key]]
  150. Dissect supports ignoring matches in the final result. This can be done with an empty key `%{}`, but for readability
  151. it may be desired to give that empty key a name.
  152. Named skip key modifier example
  153. |======
  154. | *Pattern* | `%{clientip} %{?ident} %{?auth} [%{@timestamp}]`
  155. | *Input* | 1.2.3.4 - - [30/Apr/1998:22:00:52 +0000]
  156. | *Result* a|
  157. * clientip = 1.2.3.4
  158. * @timestamp = 30/Apr/1998:22:00:52 +0000
  159. |======
  160. [[reference-keys]]
  161. ===== Reference keys (`*` and `&`)
  162. [[dissect-modifier-reference-keys]]
  163. Dissect support using parsed values as the key/value pairings for the structured content. Imagine a system that
  164. partially logs in key/value pairs. Reference keys allow you to maintain that key/value relationship.
  165. Reference key modifier example
  166. |======
  167. | *Pattern* | `[%{ts}] [%{level}] %{*p1}:%{&p1} %{*p2}:%{&p2}`
  168. | *Input* | [2018-08-10T17:15:42,466] [ERR] ip:1.2.3.4 error:REFUSED
  169. | *Result* a|
  170. * ts = 1998-08-10T17:15:42,466
  171. * level = ERR
  172. * ip = 1.2.3.4
  173. * error = REFUSED
  174. |======