|
1 | 1 | ---
|
2 | 2 | layout: default
|
3 | 3 | title: Dev Tools
|
4 |
| -nav_order: 120 |
5 |
| -has_children: true |
| 4 | +nav_order: 110 |
| 5 | +redirect_from: |
| 6 | + - /dashboards/run-queries/ |
| 7 | + - /dashboards/dev-tools/run-queries/ |
6 | 8 | ---
|
7 | 9 |
|
8 |
| -# Dev Tools |
| 10 | +# Running queries in the Dev Tools console |
9 | 11 |
|
10 |
| -**Dev Tools** is a development environment that lets you set up your OpenSearch Dashboards environment, run queries, explore data, and debug problems. You can use the Dev Tools console to: |
| 12 | +You can use the OpenSearch Dev Tools console to send queries to OpenSearch. |
11 | 13 |
|
12 |
| -- **Set up your OpenSearch Dashboards environment.** For example, you can use the console to configure authentication settings for your OpenSearch Dashboards instance. |
13 |
| -- **[Run queries to explore your data]({{site.url}}{{site.baseurl}}/dashboards/dev-tools/run-queries/).** For example, you can use the console to tune your queries for relevance. |
14 |
| -- **Debug problems with your queries.** For example, if your query is not returning the results you expect, you can use the console to identify the problem. |
15 |
| -- **Learn about the APIs in OpenSearch.** For example, you can use the API reference documentation linked in the console to look up the syntax for different API calls (select the question circle icon ({::nomarkdown}<img src="{{site.url}}{{site.baseurl}}/images/icons/question-circle.png" class="inline-icon" alt="question circle icon"/>{:/})). |
16 |
| -- **Develop custom visualizations.** For example, you can use the console to create [Vega visualizations]({{site.url}}{{site.baseurl}}/dashboards/visualize/viz-index/#vega). |
17 |
| -- **Customize the appearance and behavior of dashboards.** For example, you can use the console to customize dashboard visualization colors or to add new filters. |
| 14 | +## Navigating to the console |
18 | 15 |
|
19 |
| -To access the console, go to the OpenSearch Dashboards main menu and select **Management** > **Dev Tools**. An example is shown in the following image. |
| 16 | +To open the console, select **Dev Tools** on the main OpenSearch Dashboards page: |
20 | 17 |
|
21 |
| -<img src="{{site.url}}{{site.baseurl}}/images/dashboards/dev-tools-ui.png" alt="Dev Tools console interface" width="700"/> |
| 18 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-main.png" alt="Dev Tools console from main page">{: .img-fluid } |
| 19 | + |
| 20 | +You can open the console from any other page by navigating to the main menu and selecting **Management** > **Dev Tools**. |
| 21 | + |
| 22 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-left.png" width=200 alt="Dev Tools console from all pages"> |
| 23 | + |
| 24 | +## Writing queries |
| 25 | + |
| 26 | +Write your queries in the editor pane on the left side of the console: |
| 27 | + |
| 28 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-request.png" alt="Request pane">{: .img-fluid } |
| 29 | + |
| 30 | +You can collapse and expand parts of your query by selecting the small triangles next to the line numbers. |
| 31 | +{: .tip} |
| 32 | + |
| 33 | +To learn more about writing queries in OpenSearch domain-specific language (DSL), see [Query DSL]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/). |
| 34 | + |
| 35 | +You can import or export queries by selecting **Import** or **Export** from the top menu. |
| 36 | + |
| 37 | +### Comments |
| 38 | + |
| 39 | +Use `#` at the beginning of a line to write single-line comments. |
| 40 | + |
| 41 | +### Autocomplete |
| 42 | + |
| 43 | +OpenSearch provides autocomplete suggestions for fields, indexes and their aliases, and templates. To configure autocomplete preferences, update them in [Console Settings](#updating-the-console-settings). |
| 44 | + |
| 45 | +## Sending the request |
| 46 | + |
| 47 | +To send a query to OpenSearch, select the query by placing the cursor anywhere in the query text. Then choose the play icon ({::nomarkdown}<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/play-icon.png" class="inline-icon" alt="play icon"/>{:/}) on the upper right of the request or press `Ctrl/Cmd+Enter`: |
| 48 | + |
| 49 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-send.png" alt="Send request"> |
| 50 | + |
| 51 | +OpenSearch displays the response in the response pane on the right side of the console: |
| 52 | + |
| 53 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-response.png" alt="Response pane">{: .img-fluid } |
| 54 | + |
| 55 | +## Working in the cURL and console formats |
| 56 | + |
| 57 | +The console uses an easier syntax to format REST requests than the `curl` command. |
| 58 | + |
| 59 | +For example, the following `curl` command runs a search query: |
| 60 | + |
| 61 | +```bash |
| 62 | +curl -XGET http://localhost:9200/shakespeare/_search?pretty -H 'Content-Type: application/json' -d' |
| 63 | +{ |
| 64 | + "query": { |
| 65 | + "match": { |
| 66 | + "text_entry": "To be, or not to be" |
| 67 | + } |
| 68 | + } |
| 69 | +}' |
| 70 | +``` |
| 71 | + |
| 72 | +The same query has a simpler syntax in the console format: |
| 73 | + |
| 74 | +```json |
| 75 | +GET shakespeare/_search |
| 76 | +{ |
| 77 | + "query": { |
| 78 | + "match": { |
| 79 | + "text_entry": "To be, or not to be" |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +If you paste a `curl` command directly into the console, the command is automatically converted into the format the console uses. |
| 86 | + |
| 87 | +To import a query in cURL format, select the query, select the wrench icon ({::nomarkdown}<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/wrench-icon.png" class="inline-icon" alt="wrench icon"/>{:/}), and choose **Copy as cURL**: |
| 88 | + |
| 89 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-tools.png" alt="Console tools"> |
| 90 | + |
| 91 | +## Using triple quotation marks in queries |
| 92 | + |
| 93 | +When writing queries containing quotation marks (`"`) and backslash (`\`) characters, you can use triple quotation marks (`"""`) to avoid escaping the characters. This format improves readability and helps avoid escape characters when writing large or complex strings, especially when working with deeply nested JSON strings. |
| 94 | + |
| 95 | +You can index a document containing special characters by escaping each special character with a backslash: |
| 96 | + |
| 97 | +```json |
| 98 | +PUT /testindex/_doc/1 |
| 99 | +{ |
| 100 | + "test_query": "{ \"query\": { \"query_string\": { \"query\": \"host:\\\"127.0.0.1\\\"\" } } }" |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +Alternatively, you can use triple quotation marks for a simpler format: |
| 105 | + |
| 106 | +``` |
| 107 | +PUT /testindex/_doc/1 |
| 108 | +{ |
| 109 | + "test_query": """{ "query": { "query_string": { "query": "host:\"127.0.0.1\"" } } }""" |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +Triple quotation marks are only supported in the Dev Tools console---not in `curl` or other HTTP clients. To import a query with triple quotation marks in cURL format, use **Copy as cURL**. |
| 114 | +{: .tip} |
| 115 | + |
| 116 | +If a response contains the `\n`, `\t`, `\`, or `"` special characters, the console formats the response using triple quotation marks. To turn off this behavior, select **Settings** from the top menu and toggle **JSON syntax**. |
| 117 | +{: .tip} |
| 118 | + |
| 119 | +## Viewing documentation |
| 120 | + |
| 121 | +To view the OpenSearch documentation, select the wrench icon ({::nomarkdown}<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/wrench-icon.png" class="inline-icon" alt="wrench icon"/>{:/}) and choose **Open documentation**. |
| 122 | + |
| 123 | +## Auto indenting |
| 124 | + |
| 125 | +To use auto indent, select the queries that you want to format, select the wrench icon ({::nomarkdown}<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/wrench-icon.png" class="inline-icon" alt="wrench icon"/>{:/}), and choose **Auto indent**. |
| 126 | + |
| 127 | +Auto indenting a collapsed query expands it. |
| 128 | + |
| 129 | +Auto indenting a well-formatted query puts the request body on a single line. This is useful for working with [bulk APIs]({{site.url}}{{site.baseurl}}/api-reference/document-apis/bulk/). |
| 130 | +{: .tip} |
| 131 | + |
| 132 | +## Viewing your request history |
| 133 | + |
| 134 | +You can view up to the 500 most recent requests that OpenSearch ran successfully. To view request history, select **History** from the top menu. If you select the request you want to view from the left pane, the query is shown in the right pane. |
| 135 | + |
| 136 | +To copy the query into the editor pane, select the query text and then select **Apply**. |
| 137 | + |
| 138 | +To clear the history, select **Clear**. |
| 139 | + |
| 140 | +## Updating the console settings |
| 141 | + |
| 142 | +To update your preferences, select **Settings** from the top menu: |
| 143 | + |
| 144 | +<img src="{{site.url}}{{site.baseurl}}/images/dev-tools/dev-tools-settings.png" width=400 alt="Settings"> |
| 145 | + |
| 146 | +## Using keyboard shortcuts |
| 147 | + |
| 148 | +To view all available keyboard shortcuts, select **Help** from the top menu. |
0 commit comments