kibana/docs/dev-tools/console/console.asciidoc
Youhei Sakurai ceb7ad761d
Sort out objectization in variable substitution (#162382)
Closes #162381

## Summary

This PR is,,,

1. Adding documentation about objectization in variable substitution.
2. Fixing a glitch in the illegal double quotes `""`.
    <details open="true"><summary>details</summary>
    
For example, `""${ZERO}""` may have substituted `"0"` but this
substitution must not occur because no quotes surround the `${ZERO}` in
the context of JSON syntax. `""${ZERO}""` is jut `${ZERO}` with forward
and training `""`.</details>
3. Promoting triple quotes `"""` as an alternative to the illegal double
quotes `""`.
    <details open="true"><summary>details</summary>
    
Now `"""${ZERO}"""` is a way to substitute `"""0"""` rather than `0`
that `"${ZERO}"` may substitute. The same as before, these single and
triple quotes work only in the request body.</details>

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

Note: Regex negative lookahead `x(?!y)` and ~~lookbehind `(?<!y)x`~~
(_EDIT: no lookbehind anymore_) assertions
([cf.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Assertions#other_assertions))
are used in this PR. So, I've checked the following steps on each
browser.

Browsers:
- Chrome 115.0.5790.102
- Firefox 115.0.2
- Edge 115.0.1901.183
- Safari 16.3 (18614.4.6.1.6) ~~CAN'T CHECK~~ - Safari has recently
added support for the negative lookbehind as per this 16.4 release note.

>
https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes
> Added support for RegExp lookbehind assertions.

Steps:
1. Go to Dev Tools > Console.
2. Click `Variables` on the top.
4. Define variable `ZERO` with `0`.
6. Run the following command.

```http
POST test/_doc
{
  "field": "${ZERO}"
}
```

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

## Release note

Improves a way of variable substitution and its documentation

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-07-27 09:30:52 +09:00

228 lines
6.2 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
Interact with the REST APIs of {es} and {kib} with *Console*. With *Console*, you can:
* Send requests and view the responses
* View API documentation
* Get your request history
To get started, open the main menu, click *Dev Tools*, then click *Console*.
[role="screenshot"]
image::dev-tools/console/images/console.png["Console"]
[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
--------------------------------------------------
When you paste the command into *Console*, {kib} automatically converts it
to *Console* syntax. Alternatively, if you want to see *Console* syntax in cURL,
click the action icon (image:dev-tools/console/images/wrench.png[]) and select *Copy as cURL*.
Once copied, the username and password will need to be provided
for the calls to work from external environments.
[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.
To configure your preferences for autocomplete, go to
<<configuring-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. Select one or more requests that you
want to format, click the action icon (image:dev-tools/console/images/wrench.png[]),
and then select *Auto indent*.
For example, you might have a request formatted like this:
[role="screenshot"]
image::dev-tools/console/images/unformatted-request.png["Unformatted request", width=75%]
*Console* adjusts the JSON body of the request to apply the indents.
[role="screenshot"]
image::dev-tools/console/images/formatted-request.png["Formatted request", width=75%]
If you select *Auto indent* on a request that is already well formatted,
*Console* collapses the request body to a single line per document.
This is helpful when working with the {es} {ref}/docs-bulk.html[bulk APIs].
[float]
[[console-request]]
=== Submit requests
When you're ready to submit the request to {es}, click the green triangle.
You can select multiple requests and submit them together.
*Console* sends the requests to {es} one by one and shows the output
in the response pane. Submitting multiple requests is helpful
when you're debugging an issue or trying query
combinations in multiple scenarios.
[float]
[[console-view-api]]
=== View API docs
To view the documentation for an API endpoint, click
the action icon (image:dev-tools/console/images/wrench.png[]) and select
*Open documentation*.
[float]
[[console-history]]
=== Get your request history
*Console* maintains a list of the last 500 requests that {es} successfully executed.
To view your most recent requests, click *History*. If you select a request
and click *Apply*, {kib} adds it to the editor at the current cursor position.
[float]
[[configuring-console]]
=== Configure Console settings
You can configure the *Console* font size, JSON syntax,
and autocomplete suggestions in *Settings*.
[role="screenshot"]
image::dev-tools/console/images/console-settings.png["Console Settings", width=60%]
[float]
[[keyboard-shortcuts]]
=== Get keyboard shortcuts
For a list of available keyboard
shortcuts, click *Help*.
[float]
[[console-settings]]
=== 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.