esql-syntax.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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-timespan-literals]]
  96. === Timespan literals
  97. Datetime intervals and timespans can be expressed using timespan literals.
  98. Timespan literals are a combination of a number and a qualifier. These
  99. qualifiers are supported:
  100. * `millisecond`/`milliseconds`
  101. * `second`/`seconds`
  102. * `minute`/`minutes`
  103. * `hour`/`hours`
  104. * `day`/`days`
  105. * `week`/`weeks`
  106. * `month`/`months`
  107. * `year`/`years`
  108. Timespan literals are not whitespace sensitive. These expressions are all valid:
  109. * `1day`
  110. * `1 day`
  111. * `1 day`