You're viewing version 2.7 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.
Query Workbench
Query Workbench is a tool within OpenSearch Dashboards. You can use Query Workbench to run on-demand SQL and PPL queries, translate queries into their equivalent REST API calls, and view and save results in different response formats.
A view of the Query Workbench interface within OpenSearch Dashboards is shown in the following image.
Prerequisites
Before getting started, make sure you have indexed your data.
For this tutorial, you can index the following sample documents. Alternatively, you can use the OpenSearch Playground, which has preloaded indexes that you can use to try out Query Workbench.
To index sample documents, send the following Bulk API request:
PUT accounts/_bulk?refresh
{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
{"index":{"_id":"6"}}
{"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN"}
{"index":{"_id":"13"}}
{"account_number":13,"balance":32838,"firstname":"Nanette","lastname":"Bates","age":28,"gender":"F","address":"789 Madison Street","employer":"Quility","email":"nanettebates@quility.com","city":"Nogal","state":"VA"}
{"index":{"_id":"18"}}
{"account_number":18,"balance":4180,"firstname":"Dale","lastname":"Adams","age":33,"gender":"M","address":"467 Hutchinson Court","email":"daleadams@boink.com","city":"Orick","state":"MD"}
Running SQL queries within Query Workbench
Follow these steps to learn how to run SQL queries against your OpenSearch data using Query Workbench:
- Access Query Workbench.
- To access Query Workbench, go to OpenSearch Dashboards and choose OpenSearch Plugins > Query Workbench from the main menu.
- Run a query.
- Select the SQL button. In the query editor, type a SQL expression and then select the Run button to run the query.
The following example query retrieves the first name, last name, and balance from the
accounts
index for accounts with a balance greater than 10,000 and sorts by balance in descending order:SELECT firstname, lastname, balance FROM accounts WHERE balance > 10000 ORDER BY balance DESC;
- View the results.
- View the results in the Results pane, which presents the query output in tabular format. You can filter and download the results as needed.
The following image shows the query editor pane and results pane for the preceding SQL query:
- Clear the query editor.
- Select the Clear button to clear the query editor and run a new query.
- Examine how the query is processed.
- Select the Explain button to examine how OpenSearch processes the query, including the steps involved and order of operations.
The following image shows the explanation of the SQL query that was run in step 2.
Running PPL queries within Query Workbench
Follow these steps to learn how to run PPL queries against your OpenSearch data using Query Workbench:
- Access Query Workbench.
- To access Query Workbench, go to OpenSearch Dashboards and choose OpenSearch Plugins > Query Workbench from the main menu.
- Run a query.
- Select the PPL button. In the query editor, type a PPL query and then select the Run button to run the query.
The following is an example query that retrieves the
firstname
andlastname
fields for documents in theaccounts
index with age greater than18
:search source=accounts | where age > 18 | fields firstname, lastname
- View the results.
- View the results in the Results pane, which presents the query output in tabular format.
The following image shows the query editor pane and results pane for the PPL query that was run in step 2:
- Clear the query editor.
- Select the Clear button to clear the query editor and run a new query.
- Examine how the query is processed.
- Select the Explain button to examine how OpenSearch processes the query, including the steps involved and order of operations.
The following image shows the explanation of the PPL query that was run in step 2.
Query Workbench does not support delete or update operations through SQL or PPL. Access to data is read-only.