index.asciidoc 3.3 KB

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