esql-syntax.asciidoc 2.5 KB

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