kibana/docs/dev-tools/console/console.asciidoc
florent-leborgne c435b57526
[Docs] Refresh dev tools Console page (#193530)
## Summary

This PR updates the docs page about using the Dev Tools Console.

Closes: https://github.com/elastic/kibana/issues/191271
2024-09-27 09:59:53 +02:00

257 lines
7.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[[console-kibana]]
== Run API requests with Console
**Console** lets you interact with https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html[{es} APIs] and https://www.elastic.co/docs/api[{kib} APIs] from within {kib}.
[role="screenshot"]
image::dev-tools/console/images/console.png["Console", width="75%"]
To go to **Console**, find **Dev Tools** in the navigation menu or use the <<kibana-navigation-search,global search bar>>.
You can also find Console directly on certain Search solution and Elasticsearch serverless project pages, where you can expand it from the footer. This Console, called **Persistent Console**, has the same capabilities and shares the same history as the Console in **Dev Tools**.
[role="screenshot"]
image::dev-tools/console/images/persistent-console.png["Console", width="75%"]
[float]
[[console-api]]
=== Write requests
*Console* understands commands in a cURL-like syntax.
For example, the following is a `GET` request to the {es} `_search` API.
[source,js]
----------------------------------
GET /_search
{
"query": {
"match_all": {}
}
}
----------------------------------
Here is the equivalent command in cURL:
[source,bash]
----------------------------------
curl -XGET "http://localhost:9200/_search" -d'
{
"query": {
"match_all": {}
}
}'
----------------------------------
Prepend requests to a {kib} API endpoint with `kbn:`
[source,bash]
--------------------------------------------------
GET kbn:/api/index_management/indices
--------------------------------------------------
[float]
[[console-autocomplete]]
==== Autocomplete
When you're typing a command, *Console* makes context-sensitive suggestions.
These suggestions show you the parameters for each API and speed up your typing.
You can configure your preferences for autocomplete in the
<<configuring-console, Console settings>>.
[float]
[[console-comments]]
==== Comments
You can write comments or temporarily disable parts of a request by using double forward slashes
or pound signs to create single-line comments.
[source,js]
----------------------------------
# This request searches all of your indices.
GET /_search
{
// The query parameter indicates query context.
"query": {
"match_all": {} // Matches all documents.
}
}
----------------------------------
You can also use a forward slash followed by an asterisk to mark the beginning of multi-line
comments. An asterisk followed by a forward slash marks the end.
[source,js]
----------------------------------
GET /_search
{
"query": {
/*"match_all": {
"boost": 1.2
}*/
"match_none": {}
}
}
----------------------------------
[float]
[[console-variables]]
==== Variables
Click *Variables* to create, edit, and delete variables.
[role="screenshot"]
image::dev-tools/console/images/variables.png["Variables", width=60%]
You can refer to these variables in the paths and bodies of your requests.
Each variable can be referenced multiple times.
[source,js]
----------------------------------
GET ${pathVariable}
{
"query": {
"match": {
"${bodyNameVariable}": "${bodyValueVariable}"
}
}
}
----------------------------------
By default, variables in the body may be substituted as a boolean, number, array, or
object by removing nearby quotes instead of a string with surrounding quotes. Triple
quotes overwrite this default behavior and enforce simple replacement as a string.
[source,js]
----------------------------------
GET /locations/_search
{
"query": {
"bool": {
"must": {
"match": {
// ${shopName} shall be replaced as a string if the variable exists.
"shop.name": """${shopName}"""
}
},
"filter": {
"geo_distance": {
"distance": "12km",
// "${pinLocation}" may be substituted with an array such as [-70, 40].
"pin.location": "${pinLocation}"
}
}
}
}
}
----------------------------------
[float]
[[auto-formatting]]
==== Auto-formatting
The auto-formatting
capability can help you format requests to be more readable. Select one or more requests that you
want to format, open the contextual menu, and then select *Auto indent*.
[float]
[[keyboard-shortcuts]]
==== Keyboard shortcuts
Go to line number::
`Ctrl/Cmd` + `L`
Auto-indent current request::
`Ctrl/Cmd` + `I`
Jump to next request end::
`Ctrl/Cmd` + `↓`
Jump to previous request end::
`Ctrl/Cmd` + `↑`
Open documentation for current request::
`Ctrl/Cmd` + `/`
Run current request::
`Ctrl/Cmd` + `Enter`
Apply current or topmost term in autocomplete menu::
`Enter` or `Tab`
Close autocomplete menu::
`Esc`
Navigate items in autocomplete menu::
`↓` + `↑`
[float]
[[console-view-api]]
==== View API docs
To view the documentation for an API endpoint, select the request, then open the contextual menu and select
*Open API reference*.
[float]
[[console-request]]
=== Run requests
When you're ready to run a request, select the request, and click the play button.
The result of the request execution is displayed in the response panel, where you can see:
* the JSON response
* the HTTP status code corresponding to the request
* The execution time, in ms.
TIP: You can select multiple requests and submit them together.
*Console* executes the requests one by one. Submitting multiple requests is helpful
when you're debugging an issue or trying query
combinations in multiple scenarios.
[float]
[[import-export-console-requests]]
=== Import and export requests
You can export requests:
* **to a TXT file**, by using the **Export requests** button. When using this method, all content of the input panel is copied, including comments, requests, and payloads. All of the formatting is preserved and allows you to re-import the file later, or to a different environment, using the **Import requests** button.
+
TIP: When importing a TXT file containing Console requests, the current content of the input panel is replaced. Export it first if you don't want to lose it, or find it in the **History** tab if you already ran the requests.
* by copying them individually as **curl**, **JavaScript**, or **Python**. To do this, select a request, then open the contextual menu and select **Copy as**. When using this action, requests are copied individually to your clipboard. You can save your favorite language to make the copy action faster the next time you use it.
+
When running copied requests from an external environment, you'll need to add https://www.elastic.co/docs/api/doc/kibana/authentication[authentication information] to the request.
[float]
[[console-history]]
=== Get your request history
*Console* maintains a list of the last 500 requests that you tried to execute.
To view them, open the *History* tab.
You can run a request from your history again by selecting the request and clicking **Add and run**. If you want to add it back to the Console input panel without running it yet, click **Add** instead. It is added to the editor at the current cursor position.
[float]
[[configuring-console]]
=== Configure Console settings
Go to the **Config** tab of **Console** to customize its display, autocomplete, and accessibility settings.
[float]
[[disable-console]]
=== Disable Console
If you dont want to use *Console*, you can disable it by setting `console.ui.enabled`
to `false` in your `kibana.yml` configuration file. Changing this setting
causes the server to regenerate assets on the next startup,
which might cause a delay before pages start being served.
You can also choose to only disable the persistent console that shows in the footer of several Kibana pages. To do that, go to **Stack Management** > **Advanced Settings**, and turn off the `devTools:enablePersistentConsole` setting.