esql-syntax.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 binary comparison operators are supported:
  57. * equality: `==`
  58. * inequality: `!=`
  59. * less than: `<`
  60. * less than or equal: `<=`
  61. * larger than: `>`
  62. * larger than or equal: `>=`
  63. The `IN` operator allows testing whether a field or expression equals
  64. an element in a list of literals, fields or expressions:
  65. [source,esql]
  66. ----
  67. include::{esql-specs}/row.csv-spec[tag=in-with-expressions]
  68. ----
  69. For string comparison using wildcards or regular expressions, use `LIKE` or
  70. `RLIKE`:
  71. * Use `LIKE` to match strings using wildcards. The following wildcard characters
  72. are supported:
  73. +
  74. --
  75. ** `*` matches zero or more characters.
  76. ** `?` matches one character.
  77. [source,esql]
  78. ----
  79. FROM employees
  80. | WHERE first_name LIKE "?b*"
  81. | PROJECT first_name, last_name
  82. ----
  83. --
  84. * Use `RLIKE` to match strings using <<regexp-syntax,regular expressions>>:
  85. +
  86. [source,esql]
  87. ----
  88. FROM employees
  89. | WHERE first_name RLIKE ".leja.*"
  90. | PROJECT first_name, last_name
  91. ----
  92. The following boolean operators are supported:
  93. * `AND`
  94. * `OR`
  95. * `NOT`
  96. [discrete]
  97. [[esql-timespan-literals]]
  98. === Timespan literals
  99. Datetime intervals and timespans can be expressed using timespan literals.
  100. Timespan literals are a combination of a number and a qualifier. These
  101. qualifiers are supported:
  102. * `millisecond`/`milliseconds`
  103. * `second`/`seconds`
  104. * `minute`/`minutes`
  105. * `hour`/`hours`
  106. * `day`/`days`
  107. * `week`/`weeks`
  108. * `month`/`months`
  109. * `year`/`years`
  110. Timespan literals are not whitespace sensitive. These expressions are all valid:
  111. * `1day`
  112. * `1 day`
  113. * `1 day`