esql-kibana.asciidoc 10 KB

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