index.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. [[esql]]
  2. = ESQL
  3. :esql-tests: {xes-repo-dir}/../../plugin/esql/qa
  4. :esql-specs: {esql-tests}/testFixtures/src/main/resources
  5. [partintro]
  6. --
  7. The {es} Query Language (ESQL) is a query language that enables the iterative
  8. exploration of data.
  9. An ESQL query consists of a series of commands, separated by pipes. Each query
  10. starts with a <<esql-source-commands,source command>>. A source command produces
  11. a table, typically with data from {es}.
  12. image::images/esql/source-command.svg[A source command producing a table from {es},align="center"]
  13. A source command can be followed by one or more
  14. <<esql-processing-commands,processing commands>>. Processing commands change an
  15. input table by adding, removing, or changing rows and columns.
  16. image::images/esql/processing-command.svg[A processing command changing an input table,align="center"]
  17. You can chain processing commands, separated by a pipe character: `|`. Each
  18. processing command works on the output table of the previous command.
  19. image::images/esql/chaining-processing-commands.svg[Processing commands can be chained,align="center"]
  20. The result of a query is the table produced by the final processing command.
  21. [discrete]
  22. [[esql-console]]
  23. === Run an ESQL query
  24. [discrete]
  25. ==== The ESQL API
  26. Use the `_esql` endpoint to run an ESQL query:
  27. [source,console]
  28. ----
  29. POST /_esql
  30. {
  31. "query": """
  32. FROM library
  33. | EVAL year = DATE_TRUNC(release_date, 1 YEARS)
  34. | STATS MAX(page_count) BY year
  35. | SORT year
  36. | LIMIT 5
  37. """
  38. }
  39. ----
  40. // TEST[setup:library]
  41. The results come back in rows:
  42. [source,console-result]
  43. ----
  44. {
  45. "columns": [
  46. { "name": "MAX(page_count)", "type": "integer"},
  47. { "name": "year" , "type": "date"}
  48. ],
  49. "values": [
  50. [268, "1932-01-01T00:00:00.000Z"],
  51. [224, "1951-01-01T00:00:00.000Z"],
  52. [227, "1953-01-01T00:00:00.000Z"],
  53. [335, "1959-01-01T00:00:00.000Z"],
  54. [604, "1965-01-01T00:00:00.000Z"]
  55. ]
  56. }
  57. ----
  58. By default, results are returned as JSON. To return results formatted as text,
  59. CSV, or TSV, use the `format` parameter:
  60. [source,console]
  61. ----
  62. POST /_esql?format=txt
  63. {
  64. "query": """
  65. FROM library
  66. | EVAL year = DATE_TRUNC(release_date, 1 YEARS)
  67. | STATS MAX(page_count) BY year
  68. | SORT year
  69. | LIMIT 5
  70. """
  71. }
  72. ----
  73. // TEST[continued]
  74. [discrete]
  75. ==== {kib}
  76. ESQL can be used in Discover to explore a data set, and in Lens to visualize it.
  77. First, enable the `enableTextBased` setting in *Advanced Settings*. Next, in
  78. Discover or Lens, from the data view dropdown, select *ESQL*.
  79. NOTE: ESQL queries in Discover and Lens are subject to the time range selected
  80. with the time filter.
  81. [discrete]
  82. [[esql-limitations]]
  83. === Limitations
  84. ESQL currently supports only the following field types:
  85. - boolean
  86. - dates
  87. - keyword family (strings)
  88. - double/float/half_float
  89. - long/int/short/byte
  90. --
  91. include::esql-get-started.asciidoc[]
  92. include::esql-syntax.asciidoc[]
  93. include::esql-source-commands.asciidoc[]
  94. include::esql-processing-commands.asciidoc[]
  95. include::esql-functions.asciidoc[]
  96. :esql-tests!:
  97. :esql-specs!: