Skip to content

Commit 8ab8d55

Browse files
florent-leborgnestratoulabenironside
authored andcommitted
Variable controls in Discover (elastic#3440)
This PR: - Adds a section about creating variable controls in Discover, with sub-sections on how to edit them and how to bring these controls over to a dashboard - Transforms certain pieces of content into content snippets that are shared between Discover and Dashboards docs as variable controls are used in both apps: code examples, control parameters. - Adds the section about "how to bring Discover sessions along with their controls to a dashboard" to the "Add controls" page in dashboards docs as well. This content is single-sourced so only maintained in one place. - Re-adds a "preview" flag to the Variable controls section in dashboard docs, that one was mistakenly removed in another PR Find page previews in one of the comments below Note: Tested on staging environment on Oct 10 Closes: elastic#3096 --------- Co-authored-by: Stratou <[email protected]> Co-authored-by: Benjamin Ironside Goldstein <[email protected]>
1 parent c62e905 commit 8ab8d55

File tree

7 files changed

+109
-37
lines changed

7 files changed

+109
-37
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
To add a Discover query to a dashboard in a way that preserves the [controls created from Discover](/explore-analyze/discover/try-esql.md#add-variable-control-discover) and also adds them to the dashboard, do as follows:
2+
3+
1. Save the {{esql}} query containing the variable control into a Discover session. If your Discover session contains several tabs, only the first tab will be imported to the dashboard.
4+
5+
1. Go to **Dashboards** and open or create one.
6+
7+
1. Select **Add**, then **From library**.
8+
9+
1. Find and select the Discover session you saved earlier.
10+
11+
A new panel appears on the dashboard with the results of the query along with any attached controls.
12+
13+
![Importing Discover controls into a dashboard](/explore-analyze/images/import-discover-control-dashboard.png " =40%")
14+
15+
:::{note}
16+
When you add a visualization to a dashboard using the {icon}`save` **Save visualization** option, controls are not added to the dashboard.
17+
:::
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**Examples**
2+
3+
* Integrate filtering into your {{esql}} experience
4+
5+
```esql
6+
| WHERE field == ?value
7+
```
8+
9+
* Fields in controls for dynamic group by
10+
11+
```esql
12+
| STATS count=COUNT(*) BY ??field
13+
```
14+
15+
* Variable time ranges? Bind function configuration settings to a control
16+
17+
```esql
18+
| BUCKET(@timestamp, ?interval),
19+
```
20+
21+
* Make the function itself dynamic
22+
23+
```esql
24+
| STATS metric = ??function
25+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* The type of the control.
2+
* For controls with **Static values**, enter available controls manually or select them from the dropdown list.
3+
* For controls with **Values from a query**, write an {{esql}} query to populate the list of options.
4+
* The name of the control. This name is used to reference the control in {{esql}} queries.
5+
* Start the name with `?` if you want the options to be simple static values.
6+
* {applies_to}`stack: ga 9.1` Start the name with `??` if you want the options to be fields or functions.
7+
* The values users can select for this control. You can add multiple values from suggested fields, or type in custom values. If you selected **Values from a query**, you must instead write an {{esql}} query at this step.
8+
* The label of the control. This is the label displayed in **Discover** or in the dashboard.
9+
* The width of the control.
10+
11+
![ESQL control settings](/explore-analyze/images/esql-visualization-control-settings.png "title =50%")

explore-analyze/dashboards/add-controls.md

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ You can add one interactive time slider control to a dashboard.
9090

9191

9292
## Add variable controls [add-variable-control]
93+
```{applies_to}
94+
stack: preview 9.0
95+
serverless: preview
96+
```
9397

9498
:::{note}
9599
In versions `9.0` and `9.1`, variable controls are called {{esql}} controls.
@@ -113,17 +117,8 @@ Only **Options lists** are supported for {{esql}}-based controls. Options can be
113117

114118
2. A menu opens to let you configure the control. This is where you can specify:
115119

116-
* The type of the control.
117-
* For controls with **Static values**, select the options available in the controls by entering them manually or by using a dropdown listing available values.
118-
* For controls with **Values from a query**, write an {{esql}} query to populate the list of options.
119-
* The name of the control. This name is used to reference the control in {{esql}} queries.
120-
* Start the name with `?` if you want the options to be simple static values.
121-
* Start the name with `??` if you want the options of the control to be fields or functions. {applies_to}`stack: ga 9.1`
122-
* The values users can select for this control. You can add multiple values from suggested fields, or type in custom values. If you selected **Values from a query**, you must instead write an {{esql}} query at this step.
123-
* The label of the control. This is the label displayed for users viewing the dashboard for that control.
124-
* The width of the control.
125-
126-
![ESQL control settings](/explore-analyze/images/esql-visualization-control-settings.png "title =50%")
120+
:::{include} ../_snippets/variable-control-form.md
121+
:::
127122

128123
3. Save the control.
129124

@@ -132,34 +127,19 @@ If you added it by starting from a query, the control is directly inserted in th
132127

133128
You can then insert it in any other {{esql}} visualization queries by typing the control's name.
134129

130+
:::{include} ../_snippets/variable-control-examples.md
131+
:::
135132

136-
**Examples**
137-
138-
* Integrate filtering into your {{esql}} experience
139-
140-
```esql
141-
| WHERE field == ?value
142-
```
143-
144-
* Fields in controls for dynamic group by
145-
146-
```esql
147-
| STATS count=COUNT(*) BY ?field
148-
```
149-
150-
* Variable time ranges? Bind function configuration settings to a control
151-
152-
```esql
153-
| BUCKET(@timestamp, ?interval),
154-
```
155-
156-
* Make the function itself dynamic
133+
![Editing {{esql}} controls from a dashboard](https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blte42dfaa404bfc2d6/67d2e31e2e4dc59da190d78f/dashboard-esql-controls.gif)
157134

158-
```esql
159-
| STATS metric = ?function
160-
```
135+
### Import a Discover query along with its controls into a dashboard
136+
```{applies_to}
137+
stack: preview 9.2
138+
serverless: preview
139+
```
161140

162-
![Editing {{esql}} controls from a dashboard](https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blte42dfaa404bfc2d6/67d2e31e2e4dc59da190d78f/dashboard-esql-controls.gif)
141+
:::{include} ../_snippets/import-discover-query-controls-into-dashboard.md
142+
:::
163143

164144
## Configure the controls settings [configure-controls-settings]
165145

explore-analyze/discover/try-esql.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,43 @@ To view or edit an index:
188188
Editing a lookup index affects all {{esql}} queries that reference it. Make sure that your changes are compatible with existing queries that use this index.
189189
:::
190190

191-
4. If you made changes, select **Save** before closing the flyout.
191+
4. If you made changes, select **Save** before closing the flyout.
192+
193+
### Add variable controls to your Discover queries [add-variable-control-discover]
194+
```{applies_to}
195+
stack: preview 9.2
196+
serverless: preview
197+
```
198+
199+
Variable controls help you make your queries more dynamic instead of having to maintain several versions of almost identical queries.
200+
201+
![Variable control in Discover](/explore-analyze/images/variable-control-discover.png " =75%")
202+
203+
You can add them from your Discover {{esql}} query.
204+
205+
1. While editing your {{esql}} query, the autocomplete menu suggests adding a control when relevant or when typing `?` in the query. Select **Create control**.
206+
207+
2. A menu opens to let you configure the control. This is where you can specify:
208+
209+
:::{include} ../_snippets/variable-control-form.md
210+
:::
211+
212+
3. Save the control.
213+
214+
The variable is inserted into your query, and the control appears in the query editor.
215+
216+
:::{include} ../_snippets/variable-control-examples.md
217+
:::
218+
219+
#### Edit a variable control
220+
221+
Once a control is active for your query, you can still edit it by hovering over it and by selecting the {icon}`pencil` **Edit** option that appears.
222+
223+
You can edit all of the options described in [](#add-variable-control-discover).
224+
225+
When you save your edits, the control is updated for your query.
226+
227+
#### Import a Discover query along with its controls into a dashboard
228+
229+
:::{include} ../_snippets/import-discover-query-controls-into-dashboard.md
230+
:::
120 KB
Loading
318 KB
Loading

0 commit comments

Comments
 (0)