index.asciidoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 `_query` endpoint to run an {esql} query:
  27. [source,console]
  28. ----
  29. POST /_query
  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 /_query?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[setup:library]
  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 the following <<mapping-types,field types>>:
  85. - `alias`
  86. - `boolean`
  87. - `date`
  88. - `ip`
  89. - `keyword` family (`keyword`, `constant_keyword`, and `wildcard`)
  90. - `double`/`float`/`half_float` (represented as `double`)
  91. - `long`
  92. - `int`/`short`/`byte` (represented as `int`)
  93. - `version`
  94. --
  95. include::esql-get-started.asciidoc[]
  96. include::esql-syntax.asciidoc[]
  97. include::esql-source-commands.asciidoc[]
  98. include::esql-processing-commands.asciidoc[]
  99. include::esql-functions.asciidoc[]
  100. include::aggregation-functions.asciidoc[]
  101. include::multivalued-fields.asciidoc[]
  102. :esql-tests!:
  103. :esql-specs!: