1
0

grok.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. [discrete]
  2. [[esql-grok]]
  3. === `GROK`
  4. `GROK` enables you to <<esql-process-data-with-dissect-and-grok,extract
  5. structured data out of a string>>.
  6. **Syntax**
  7. [source,esql]
  8. ----
  9. GROK input "pattern"
  10. ----
  11. *Parameters*
  12. `input`::
  13. The column that contains the string you want to structure. If the column has
  14. multiple values, `GROK` will process each value.
  15. `pattern`::
  16. A grok pattern.
  17. If a field name conflicts with an existing column, the existing column is discarded.
  18. If a field name is used more than once, a multi-valued column will be created with one value
  19. per each occurrence of the field name.
  20. *Description*
  21. `GROK` enables you to <<esql-process-data-with-dissect-and-grok,extract
  22. structured data out of a string>>. `GROK` matches the string against patterns,
  23. based on regular expressions, and extracts the specified patterns as columns.
  24. Refer to <<esql-process-data-with-grok>> for the syntax of grok patterns.
  25. *Examples*
  26. // tag::examples[]
  27. The following example parses a string that contains a timestamp, an IP address,
  28. an email address, and a number:
  29. [source.merge.styled,esql]
  30. ----
  31. include::{esql-specs}/docs.csv-spec[tag=basicGrok]
  32. ----
  33. [%header.monospaced.styled,format=dsv,separator=|]
  34. |===
  35. include::{esql-specs}/docs.csv-spec[tag=basicGrok-result]
  36. |===
  37. By default, `GROK` outputs keyword string columns. `int` and `float` types can
  38. be converted by appending `:type` to the semantics in the pattern. For example
  39. `{NUMBER:num:int}`:
  40. [source.merge.styled,esql]
  41. ----
  42. include::{esql-specs}/docs.csv-spec[tag=grokWithConversionSuffix]
  43. ----
  44. [%header.monospaced.styled,format=dsv,separator=|]
  45. |===
  46. include::{esql-specs}/docs.csv-spec[tag=grokWithConversionSuffix-result]
  47. |===
  48. For other type conversions, use <<esql-type-conversion-functions>>:
  49. [source.merge.styled,esql]
  50. ----
  51. include::{esql-specs}/docs.csv-spec[tag=grokWithToDatetime]
  52. ----
  53. [%header.monospaced.styled,format=dsv,separator=|]
  54. |===
  55. include::{esql-specs}/docs.csv-spec[tag=grokWithToDatetime-result]
  56. |===
  57. If a field name is used more than once, `GROK` creates a multi-valued
  58. column:
  59. [source.merge.styled,esql]
  60. ----
  61. include::{esql-specs}/docs.csv-spec[tag=grokWithDuplicateFieldNames]
  62. ----
  63. [%header.monospaced.styled,format=dsv,separator=|]
  64. |===
  65. include::{esql-specs}/docs.csv-spec[tag=grokWithDuplicateFieldNames-result]
  66. |===
  67. // end::examples[]