esql-syntax.asciidoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-source-commands,source command>> followed
  10. by an optional series of <<esql-processing-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 readability, this documentation puts each processing command on a new line.
  20. However, you can write an {esql} query as a single line. The following query is
  21. identical to the previous one:
  22. [source,esql]
  23. ----
  24. source-command | processing-command1 | processing-command2
  25. ----
  26. [discrete]
  27. [[esql-comments]]
  28. === Comments
  29. {esql} uses C++ style comments:
  30. * double slash `//` for single line comments
  31. * `/*` and `*/` for block comments
  32. [source,esql]
  33. ----
  34. // Query the employees index
  35. FROM employees
  36. | WHERE height > 2
  37. ----
  38. [source,esql]
  39. ----
  40. FROM /* Query the employees index */ employees
  41. | WHERE height > 2
  42. ----
  43. [source,esql]
  44. ----
  45. FROM employees
  46. /* Query the
  47. * employees
  48. * index */
  49. | WHERE height > 2
  50. ----
  51. [discrete]
  52. [[esql-operators]]
  53. === Operators
  54. These binary comparison operators are supported:
  55. * equality: `==`
  56. * inequality: `!=`
  57. * less than: `<`
  58. * less than or equal: `<=`
  59. * larger than: `>`
  60. * larger than or equal: `>=`
  61. The `IN` operator allows testing whether a field or expression equals
  62. an element in a list of literals, fields or expressions:
  63. [source,esql]
  64. ----
  65. include::{esql-specs}/row.csv-spec[tag=in-with-expressions]
  66. ----
  67. For string comparison using wildcards or regular expressions, use `LIKE` or
  68. `RLIKE`:
  69. * Use `LIKE` to match strings using wildcards. The following wildcard characters
  70. are supported:
  71. +
  72. --
  73. ** `*` matches zero or more characters.
  74. ** `?` matches one character.
  75. [source,esql]
  76. ----
  77. FROM employees
  78. | WHERE first_name LIKE "?b*"
  79. | KEEP first_name, last_name
  80. ----
  81. --
  82. * Use `RLIKE` to match strings using <<regexp-syntax,regular expressions>>:
  83. +
  84. [source,esql]
  85. ----
  86. FROM employees
  87. | WHERE first_name RLIKE ".leja.*"
  88. | KEEP first_name, last_name
  89. ----
  90. The following boolean operators are supported:
  91. * `AND`
  92. * `OR`
  93. * `NOT`
  94. [discrete]
  95. [[esql-predicates]]
  96. === Predicates
  97. For NULL comparison use the `IS NULL` and `IS NOT NULL` predicates:
  98. [source.merge.styled,esql]
  99. ----
  100. include::{esql-specs}/null.csv-spec[tag=is-null]
  101. ----
  102. [%header.monospaced.styled,format=dsv,separator=|]
  103. |===
  104. include::{esql-specs}/null.csv-spec[tag=is-null-result]
  105. |===
  106. [source.merge.styled,esql]
  107. ----
  108. include::{esql-specs}/null.csv-spec[tag=is-not-null]
  109. ----
  110. [%header.monospaced.styled,format=dsv,separator=|]
  111. |===
  112. include::{esql-specs}/null.csv-spec[tag=is-not-null-result]
  113. |===
  114. [discrete]
  115. [[esql-timespan-literals]]
  116. === Timespan literals
  117. Datetime intervals and timespans can be expressed using timespan literals.
  118. Timespan literals are a combination of a number and a qualifier. These
  119. qualifiers are supported:
  120. * `millisecond`/`milliseconds`
  121. * `second`/`seconds`
  122. * `minute`/`minutes`
  123. * `hour`/`hours`
  124. * `day`/`days`
  125. * `week`/`weeks`
  126. * `month`/`months`
  127. * `year`/`years`
  128. Timespan literals are not whitespace sensitive. These expressions are all valid:
  129. * `1day`
  130. * `1 day`
  131. * `1 day`