Translate SQL into Elasticsearch queries Generally available; Added in 6.3.0

GET /_sql/translate

All methods and paths for this operation:

POST /_sql/translate

GET /_sql/translate

Translate an SQL search into a search API request containing Query DSL. It accepts the same request body parameters as the SQL search API, excluding cursor.

Required authorization

  • Index privileges: read
application/json

Body Required

  • fetch_size number

    The maximum number of rows (or entries) to return in one response.

    Default value is 1000.

  • filter object

    The Elasticsearch query DSL for additional filtering.

    External documentation
  • query string Required

    The SQL query to run.

  • time_zone string

    The ISO-8601 time zone ID for the search.

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • aggregations object
    • size number
    • _source boolean | object

      One of:
    • fields array[object]

      A reference to a field with formatting instructions on how to return the value

      Hide fields attributes Show fields attributes object
      • field string Required

        A wildcard pattern. The request returns values for field names matching this pattern.

      • format string

        The format in which the values are returned.

      • include_unmapped boolean
    • query object

      An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.

      External documentation
    • sort string | object | array[string | object]

      One of:

      Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

    • track_total_hits boolean | number

      Number of hits matching the query to count accurately. If true, the exact number of hits is returned at the cost of some performance. If false, the response does not include the total number of hits matching the query. Defaults to 10,000 hits.

GET /_sql/translate
POST _sql/translate { "query": "SELECT * FROM library ORDER BY page_count DESC", "fetch_size": 10 }
resp = client.sql.translate( query="SELECT * FROM library ORDER BY page_count DESC", fetch_size=10, )
const response = await client.sql.translate({ query: "SELECT * FROM library ORDER BY page_count DESC", fetch_size: 10, });
response = client.sql.translate( body: { "query": "SELECT * FROM library ORDER BY page_count DESC", "fetch_size": 10 } )
$resp = $client->sql()->translate([ "body" => [ "query" => "SELECT * FROM library ORDER BY page_count DESC", "fetch_size" => 10, ], ]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"query":"SELECT * FROM library ORDER BY page_count DESC","fetch_size":10}' "$ELASTICSEARCH_URL/_sql/translate"
client.sql().translate(t -> t .fetchSize(10) .query("SELECT * FROM library ORDER BY page_count DESC") ); 
Request example
{ "query": "SELECT * FROM library ORDER BY page_count DESC", "fetch_size": 10 }