index.asciidoc 3.4 KB

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