esql-syntax.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. [[esql-syntax]]
  2. === {esql} syntax reference
  3. ++++
  4. <titleabbrev>Syntax reference</titleabbrev>
  5. ++++
  6. [discrete]
  7. [[esql-basic-syntax]]
  8. === Basic syntax
  9. An {esql} query is composed of a <<esql-commands,source command>> followed
  10. by an optional series of <<esql-commands,processing commands>>,
  11. separated by a pipe character: `|`. For example:
  12. [source,esql]
  13. ----
  14. source-command
  15. | processing-command1
  16. | processing-command2
  17. ----
  18. The result of a query is the table produced by the final processing command.
  19. For an overview of all supported commands, functions, and operators, refer to <<esql-commands>> and <<esql-functions-operators>>.
  20. [NOTE]
  21. ====
  22. For readability, this documentation puts each processing command on a new
  23. line. However, you can write an {esql} query as a single line. The following
  24. query is identical to the previous one:
  25. [source,esql]
  26. ----
  27. source-command | processing-command1 | processing-command2
  28. ----
  29. ====
  30. [discrete]
  31. [[esql-identifiers]]
  32. ==== Identifiers
  33. Identifiers need to be quoted with backticks (+{backtick}+) if:
  34. * they don't start with a letter, `_` or `@`
  35. * any of the other characters is not a letter, number, or `_`
  36. For example:
  37. [source,esql]
  38. ----
  39. FROM index
  40. | KEEP `1.field`
  41. ----
  42. When referencing a function alias that itself uses a quoted identifier, the
  43. backticks of the quoted identifier need to be escaped with another backtick. For
  44. example:
  45. [source,esql]
  46. ----
  47. FROM index
  48. | STATS COUNT(`1.field`)
  49. | EVAL my_count = `COUNT(``1.field``)`
  50. ----
  51. [discrete]
  52. [[esql-literals]]
  53. ==== Literals
  54. {esql} currently supports numeric and string literals.
  55. [discrete]
  56. [[esql-string-literals]]
  57. ===== String literals
  58. A string literal is a sequence of unicode characters delimited by double
  59. quotes (`"`).
  60. [source,esql]
  61. ----
  62. // Filter by a string value
  63. FROM index
  64. | WHERE first_name == "Georgi"
  65. ----
  66. If the literal string itself contains quotes, these need to be escaped (`\\"`).
  67. {esql} also supports the triple-quotes (`"""`) delimiter, for convenience:
  68. [source,esql]
  69. ----
  70. ROW name = """Indiana "Indy" Jones"""
  71. ----
  72. The special characters CR, LF and TAB can be provided with the usual escaping:
  73. `\r`, `\n`, `\t`, respectively.
  74. [discrete]
  75. [[esql-numeric-literals]]
  76. ===== Numerical literals
  77. The numeric literals are accepted in decimal and in the scientific notation
  78. with the exponent marker (`e` or `E`), starting either with a digit, decimal
  79. point `.` or the negative sign `-`:
  80. [source, sql]
  81. ----
  82. 1969 -- integer notation
  83. 3.14 -- decimal notation
  84. .1234 -- decimal notation starting with decimal point
  85. 4E5 -- scientific notation (with exponent marker)
  86. 1.2e-3 -- scientific notation with decimal point
  87. -.1e2 -- scientific notation starting with the negative sign
  88. ----
  89. The integer numeric literals are implicitly converted to the `integer`, `long`
  90. or the `double` type, whichever can first accommodate the literal's value.
  91. The floating point literals are implicitly converted the `double` type.
  92. To obtain constant values of different types, use one of the numeric
  93. <<esql-type-conversion-functions, conversion functions>>.
  94. [discrete]
  95. [[esql-comments]]
  96. ==== Comments
  97. {esql} uses C++ style comments:
  98. * double slash `//` for single line comments
  99. * `/*` and `*/` for block comments
  100. [source,esql]
  101. ----
  102. // Query the employees index
  103. FROM employees
  104. | WHERE height > 2
  105. ----
  106. [source,esql]
  107. ----
  108. FROM /* Query the employees index */ employees
  109. | WHERE height > 2
  110. ----
  111. [source,esql]
  112. ----
  113. FROM employees
  114. /* Query the
  115. * employees
  116. * index */
  117. | WHERE height > 2
  118. ----
  119. [discrete]
  120. [[esql-timespan-literals]]
  121. ==== Timespan literals
  122. Datetime intervals and timespans can be expressed using timespan literals.
  123. Timespan literals are a combination of a number and a qualifier. These
  124. qualifiers are supported:
  125. * `millisecond`/`milliseconds`/`ms`
  126. * `second`/`seconds`/`sec`/`s`
  127. * `minute`/`minutes`/`min`
  128. * `hour`/`hours`/`h`
  129. * `day`/`days`/`d`
  130. * `week`/`weeks`/`w`
  131. * `month`/`months`/`mo`
  132. * `quarter`/`quarters`/`q`
  133. * `year`/`years`/`yr`/`y`
  134. Timespan literals are not whitespace sensitive. These expressions are all valid:
  135. * `1day`
  136. * `1 day`
  137. * `1 day`