dissect.asciidoc 8.9 KB

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