esql-syntax.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. [[esql-syntax]]
  2. == ESQL syntax reference
  3. ++++
  4. <titleabbrev>Syntax reference</titleabbrev>
  5. ++++
  6. :keywords: {es}, ESQL, {es} query language, syntax
  7. :description: An ESQL query is composed of a source command followed by an optional series of processing commands, separated by a pipe character.
  8. [discrete]
  9. [[esql-basic-syntax]]
  10. === Basic syntax
  11. An ESQL query is composed of a <<esql-source-commands,source command>> followed
  12. by an optional series of <<esql-processing-commands,processing commands>>,
  13. separated by a pipe character: `|`. For example:
  14. [source,esql]
  15. ----
  16. source-command
  17. | processing-command1
  18. | processing-command2
  19. ----
  20. The result of a query is the table produced by the final processing command.
  21. For readability, this documentation puts each processing command on a new line.
  22. However, you can write an ESQL query as a single line. The following query is
  23. identical to the previous one:
  24. [source,esql]
  25. ----
  26. source-command | processing-command1 | processing-command2
  27. ----
  28. [discrete]
  29. [[esql-comments]]
  30. === Comments
  31. ESQL uses C++ style comments:
  32. * double slash `//` for single line comments
  33. * `/*` and `*/` for block comments
  34. [source,esql]
  35. ----
  36. // Query the employees index
  37. FROM employees
  38. | WHERE height > 2
  39. ----
  40. [source,esql]
  41. ----
  42. FROM /* Query the employees index */ employees
  43. | WHERE height > 2
  44. ----
  45. [source,esql]
  46. ----
  47. FROM employees
  48. /* Query the
  49. * employees
  50. * index */
  51. | WHERE height > 2
  52. ----
  53. [discrete]
  54. [[esql-operators]]
  55. === Operators
  56. These comparison operators are supported:
  57. * equality: `==`
  58. * inequality: `!=`
  59. * comparison:
  60. ** less than: `<`
  61. ** less than or equal: `<=`
  62. ** larger than: `>`
  63. ** larger than or equal: `>=`
  64. For string comparison using wildcards or regular expressions, use `LIKE` or
  65. `RLIKE`:
  66. * Use `LIKE` to match strings using wildcards. The following wildcard characters
  67. are supported:
  68. +
  69. --
  70. ** `*` matches zero or more characters.
  71. ** `?` matches one character.
  72. [source,esql]
  73. ----
  74. FROM employees
  75. | WHERE first_name LIKE "?b*"
  76. | PROJECT first_name, last_name
  77. ----
  78. --
  79. * Use `RLIKE` to match strings using <<regexp-syntax,regular expressions>>:
  80. +
  81. [source,esql]
  82. ----
  83. FROM employees
  84. | WHERE first_name RLIKE ".leja.*"
  85. | PROJECT first_name, last_name
  86. ----
  87. The following boolean operators are supported:
  88. * `AND`
  89. * `OR`
  90. * `NOT`
  91. [discrete]
  92. [[esql-timespan-literals]]
  93. === Timespan literals
  94. Datetime intervals and timespans can be expressed using timespan literals.
  95. Timespan literals are a combination of a number and a qualifier. These
  96. qualifiers are supported:
  97. * `millisecond`/`milliseconds`
  98. * `second`/`seconds`
  99. * `minute`/`minutes`
  100. * `hour`/`hours`
  101. * `day`/`days`
  102. * `week`/`weeks`
  103. * `month`/`months`
  104. * `year`/`years`
  105. Timespan literals are not whitespace sensitive. These expressions are all valid:
  106. * `1day`
  107. * `1 day`
  108. * `1 day`