esql-kibana.asciidoc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. [[esql-kibana]]
  2. === Using {esql} in {kib}
  3. ++++
  4. <titleabbrev>Using {esql} in {kib}</titleabbrev>
  5. ++++
  6. You can use {esql} in {kib} to query and aggregate your data, create
  7. visualizations, and set up alerts.
  8. This guide shows you how to use {esql} in Kibana. To follow along with the
  9. queries, load the "Sample web logs" sample data set by clicking *Try sample
  10. data* from the {kib} Home, selecting *Other sample data sets*, and clicking *Add
  11. data* on the *Sample web logs* card.
  12. [discrete]
  13. [[esql-kibana-get-started]]
  14. === Get started with {esql}
  15. // tag::esql-mode[]
  16. To get started with {esql} in Discover, open the main menu and select
  17. *Discover*. Next, from the Data views menu, select *Try ES|QL*.
  18. image::images/esql/esql-data-view-menu.png[align="center",width=33%]
  19. // end::esql-mode[]
  20. The ability to select {esql} from the Data views menu can be enabled and
  21. disabled using the `discover:enableESQL` setting from
  22. {kibana-ref}/advanced-options.html[Advanced Settings].
  23. [discrete]
  24. [[esql-kibana-query-bar]]
  25. === The query bar
  26. After switching to {esql} mode, the query bar shows a sample query. For example:
  27. [source,esql]
  28. ----
  29. from kibana_sample_data_logs | limit 10
  30. ----
  31. Every query starts with a <<esql-commands,source command>>. In this query, the
  32. source command is <<esql-from>>. `FROM` retrieves data from data streams, indices, or
  33. aliases. In this example, the data is retrieved from `kibana_sample_data_logs`.
  34. A source command can be followed by one or more <<esql-commands,processing
  35. commands>>. In this query, the processing command is <<esql-limit>>. `LIMIT`
  36. limits the number of rows that are retrieved.
  37. TIP: Click the help icon (image:images/esql/esql-icon-help.svg[]) to open the
  38. in-product reference documentation for all commands and functions.
  39. // tag::autocomplete[]
  40. To make it easier to write queries, auto-complete offers suggestions with
  41. possible commands and functions:
  42. image::images/esql/esql-kibana-auto-complete.png[align="center"]
  43. // end::autocomplete[]
  44. [NOTE]
  45. ====
  46. {esql} keywords are case-insensitive. The following query is identical to the
  47. previous one:
  48. [source,esql]
  49. ----
  50. FROM kibana_sample_data_logs | LIMIT 10
  51. ----
  52. ====
  53. [discrete]
  54. ==== Expand the query bar
  55. For readability, you can put each processing command on a new line. The
  56. following query is identical to the previous one:
  57. [source,esql]
  58. ----
  59. FROM kibana_sample_data_logs
  60. | LIMIT 10
  61. ----
  62. // tag::compact[]
  63. To make it easier to write multi-line queries, click the double-headed arrow
  64. button (image:images/esql/esql-icon-expand-query-bar.svg[]) to expand the query
  65. bar:
  66. image::images/esql/esql-expanded-query-bar.png[align="center"]
  67. To return to a compact query bar, click the minimize editor button
  68. (image:images/esql/esql-icon-minimize-query-bar.svg[]).
  69. // end::compact[]
  70. [discrete]
  71. ==== Warnings
  72. A query may result in warnings, for example when querying an unsupported field
  73. type. When that happens, a warning symbol is shown in the query bar. To see the
  74. detailed warning, expand the query bar, and click *warnings*.
  75. [discrete]
  76. [[esql-kibana-results-table]]
  77. === The results table
  78. For the example query, the results table shows 10 rows. Omitting the `LIMIT`
  79. command, the results table defaults to up to 500 rows. Using `LIMIT`, you can
  80. increase the limit to up to 10,000 rows.
  81. NOTE: the 10,000 row limit only applies to the number of rows that are retrieved
  82. by the query and displayed in Discover. Any query or aggregation runs on the
  83. full data set.
  84. Each row shows two columns for the example query: a column with the `@timestamp`
  85. field and a column with the full document. To display specific fields from the
  86. documents, use the <<esql-keep>> command:
  87. [source,esql]
  88. ----
  89. FROM kibana_sample_data_logs
  90. | KEEP @timestamp, bytes, geo.dest
  91. ----
  92. To display all fields as separate columns, use `KEEP *`:
  93. [source,esql]
  94. ----
  95. FROM kibana_sample_data_logs
  96. | KEEP *
  97. ----
  98. NOTE: The maximum number of columns in Discover is 50. If a query returns more
  99. than 50 columns, Discover only shows the first 50.
  100. [discrete]
  101. ==== Sorting
  102. To sort on one of the columns, click the column name you want to sort on and
  103. select the sort order. Note that this performs client-side sorting. It only
  104. sorts the rows that were retrieved by the query, which may not be the full
  105. dataset because of the (implicit) limit. To sort the full data set, use the
  106. <<esql-sort>> command:
  107. [source,esql]
  108. ----
  109. FROM kibana_sample_data_logs
  110. | KEEP @timestamp, bytes, geo.dest
  111. | SORT bytes DESC
  112. ----
  113. [discrete]
  114. [[esql-kibana-time-filter]]
  115. === Time filtering
  116. To display data within a specified time range, use the
  117. {kibana-ref}/set-time-filter.html[time filter]. The time filter is only enabled
  118. when the indices you're querying have a field called `@timestamp`.
  119. If your indices do not have a timestamp field called `@timestamp`, you can limit
  120. the time range using the <<esql-where>> command and the <<esql-now>> function.
  121. For example, if the timestamp field is called `timestamp`, to query the last 15
  122. minutes of data:
  123. [source,esql]
  124. ----
  125. FROM kibana_sample_data_logs
  126. | WHERE timestamp > NOW() - 15minutes
  127. ----
  128. [discrete]
  129. [[esql-kibana-visualizations]]
  130. === Analyze and visualize data
  131. Between the query bar and the results table, Discover shows a date histogram
  132. visualization. If the indices you're querying do not contain an `@timestamp`
  133. field, the histogram is not shown.
  134. The visualization adapts to the query. A query's nature determines the type of
  135. visualization. For example, this query aggregates the total number of bytes per
  136. destination country:
  137. [source,esql]
  138. ----
  139. FROM kibana_sample_data_logs
  140. | STATS total_bytes = SUM(bytes) BY geo.dest
  141. | SORT total_bytes DESC
  142. | LIMIT 3
  143. ----
  144. The resulting visualization is a bar chart showing the top 3 countries:
  145. image::images/esql/esql-kibana-bar-chart.png[align="center"]
  146. To change the visualization into another type, click the visualization type
  147. dropdown:
  148. image::images/esql/esql-kibana-visualization-type.png[align="center",width=33%]
  149. To make other changes to the visualization, like the axes and colors, click the
  150. pencil button (image:images/esql/esql-icon-edit-visualization.svg[]). This opens
  151. an in-line editor:
  152. image::images/esql/esql-kibana-in-line-editor.png[align="center"]
  153. You can save the visualization to a new or existing dashboard by clicking the
  154. save button (image:images/esql/esql-icon-save-visualization.svg[]). Once saved
  155. to a dashboard, you can continue to make changes to visualization. Click the
  156. options button in the top-right (image:images/esql/esql-icon-options.svg[]) and
  157. select *Edit ESQL visualization* to open the in-line editor:
  158. image::images/esql/esql-kibana-edit-on-dashboard.png[align="center"]
  159. [discrete]
  160. [[esql-kibana-enrich]]
  161. === Create an enrich policy
  162. The {esql} <<esql-enrich>> command enables you to <<esql-enrich-data,enrich>>
  163. your query dataset with fields from another dataset. Before you can use
  164. `ENRICH`, you need to <<esql-set-up-enrich-policy,create and execute an enrich
  165. policy>>. If a policy exists, it will be suggested by auto-complete. If not,
  166. click *Click to create* to create one.
  167. image::images/esql/esql-kibana-enrich-autocomplete.png[align="center"]
  168. Next, you can enter a policy name, the policy type, source indices, and
  169. optionally a query:
  170. image::images/esql/esql-kibana-enrich-step-1.png[align="center",width="50%"]
  171. Click *Next* to select the match field and enrich fields:
  172. image::images/esql/esql-kibana-enrich-step-2.png[align="center",width="50%"]
  173. Finally, click *Create and execute*.
  174. Now, you can use the enrich policy in an {esql} query:
  175. image::images/esql/esql-kibana-enriched-data.png[align="center"]
  176. [discrete]
  177. [[esql-kibana-alerting-rule]]
  178. === Create an alerting rule
  179. You can use {esql} queries to create alerts. From Discover, click *Alerts* and
  180. select *Create search threshold rule*. This opens a panel that enables you to
  181. create a rule using an {esql} query. Next, you can test the query, add a
  182. connector, and save the rule.
  183. image::images/esql/esql-kibana-create-rule.png[align="center",width=50%]
  184. [discrete]
  185. [[esql-kibana-limitations]]
  186. === Limitations
  187. // tag::limitations[]
  188. * The user interface to filter data is not enabled when Discover is in {esql}
  189. mode. To filter data, write a query that uses the <<esql-where>> command
  190. instead.
  191. * In {esql} mode, clicking a field in the field list in Discover does not show
  192. quick statistics for that field.
  193. * Discover shows no more than 10,000 rows. This limit only applies to the number
  194. of rows that are retrieved by the query and displayed in Discover. Queries and
  195. aggregations run on the full data set.
  196. * Discover shows no more than 50 columns. If a query returns
  197. more than 50 columns, Discover only shows the first 50.
  198. * Querying many many indices at once without any filters can cause an error in
  199. kibana which looks like `[esql] > Unexpected error from Elasticsearch: The
  200. content length (536885793) is bigger than the maximum allowed string
  201. (536870888)`. The response from {esql} is too long. Use <<esql-drop>> or
  202. <<esql-keep>> to limit the number of fields returned.
  203. // end::limitations[]