Translate SQL into Elasticsearch queries Generally available; Added in 6.3.0

POST /_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

Responses

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

      Defines how to fetch a source. Fetching can be disabled entirely, or the source can be filtered.

      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

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

      • format string

        The format in which the values are returned.

    • 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.

      One of:

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

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"
Request example
{
  "query": "SELECT * FROM library ORDER BY page_count DESC",
  "fetch_size": 10
}