SQL

SQL in OpenSearch bridges the gap between traditional relational database concepts and the flexibility of OpenSearch’s document-oriented data storage. This integration gives you the ability to use your SQL knowledge to query, analyze, and extract insights from your OpenSearch data.

SQL and OpenSearch terminology

Here’s how core SQL concepts map to OpenSearch:

SQLOpenSearch
TableIndex
RowDocument
ColumnField

REST API

For a complete REST API reference for the SQL plugin, see SQL/PPL API.

To use the SQL plugin with your own applications, send requests to the _plugins/_sql endpoint:

  1. POST _plugins/_sql
  2. {
  3. "query": "SELECT * FROM my-index LIMIT 50"
  4. }

copy

You can query multiple indexes by using a comma-separated list:

  1. POST _plugins/_sql
  2. {
  3. "query": "SELECT * FROM my-index1,myindex2,myindex3 LIMIT 50"
  4. }

copy

You can specify an index pattern with a wildcard expression:

  1. POST _plugins/_sql
  2. {
  3. "query": "SELECT * FROM my-index* LIMIT 50"
  4. }

copy

To run the preceding query in the command line, use the curl command:

  1. curl -XPOST https://localhost:9200/_plugins/_sql -u 'admin:admin' -k -H 'Content-Type: application/json' -d '{"query": "SELECT * FROM my-index* LIMIT 50"}'

copy

You can specify the response format as JDBC, standard OpenSearch JSON, CSV, or raw. By default, queries return data in JDBC format. The following query sets the format to JSON:

  1. POST _plugins/_sql?format=json
  2. {
  3. "query": "SELECT * FROM my-index LIMIT 50"
  4. }

copy

For more information about request parameters, settings, supported operations, and tools, see the related topics under SQL.