index.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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(1 YEARS, release_date)
  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(1 YEARS, release_date)
  68. | STATS MAX(page_count) BY year
  69. | SORT year
  70. | LIMIT 5
  71. """
  72. }
  73. ----
  74. // TEST[setup:library]
  75. The above query's `LIMIT` command limits results to 5 rows.
  76. If not specified, `LIMIT` defaults to `500`. A single query will not return
  77. more than 10,000 rows, regardless of the `LIMIT` value.
  78. [discrete]
  79. ==== {kib}
  80. Use {esql} in Discover to explore a data set. From the data view dropdown,
  81. select *Try {esql}* to get started.
  82. NOTE: {esql} queries in Discover and Lens are subject to the time range selected
  83. with the time filter.
  84. [discrete]
  85. [[esql-limitations]]
  86. === Limitations
  87. * {esql} currently supports the following <<mapping-types,field types>>:
  88. ** `alias`
  89. ** `boolean`
  90. ** `date`
  91. ** `double` (`float`, `half_float`, `scaled_float` are represented as `double`)
  92. ** `ip`
  93. ** `keyword` family including `keyword`, `constant_keyword`, and `wildcard`
  94. ** `int` (`short` and `byte` are represented as `int`)
  95. ** `long`
  96. ** `null`
  97. ** `text`
  98. ** `unsigned_long`
  99. ** `version`
  100. * A single query will not return more than 10,000 rows, regardless of the
  101. `LIMIT` command's value.
  102. --
  103. include::esql-get-started.asciidoc[]
  104. include::esql-syntax.asciidoc[]
  105. include::esql-source-commands.asciidoc[]
  106. include::esql-processing-commands.asciidoc[]
  107. include::esql-functions.asciidoc[]
  108. include::aggregation-functions.asciidoc[]
  109. include::multivalued-fields.asciidoc[]
  110. include::metadata-fields.asciidoc[]
  111. include::task-management.asciidoc[]
  112. :esql-tests!:
  113. :esql-specs!: