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

  • fetch_size number

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

  • filter object

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

    External documentation
  • query string Required

    The SQL query to run.

  • time_zone string

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • aggregations 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.

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

      One of:

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

POST /_sql/translate
curl \ --request POST 'http://api.example.com/_sql/translate' \ --header "Authorization: $API_KEY" \ --header "Content-Type: application/json" \ --data '"{\n \"query\": \"SELECT * FROM library ORDER BY page_count DESC\",\n \"fetch_size\": 10\n}"'
Request example
{ "query": "SELECT * FROM library ORDER BY page_count DESC", "fetch_size": 10 }