Get SQL search results Generally available; Added in 6.3.0

GET /_sql

All methods and paths for this operation:

POST /_sql

GET /_sql

Run an SQL request.

highlight#highlightFromAnchor" href="#topic-required-authorization"> Required authorization

  • Index privileges: read

Query parameters

  • format string

    The format for the response. You can also specify a format using the Accept HTTP header. If you specify both this parameter and the Accept HTTP header, this parameter takes precedence.

    Values are csv, json, tsv, txt, yaml, cbor, or smile.

application/json

Body Required

Responses

  • 200 application/json
    details#setActive"> Hide response attributes Show response attributes object
    • columns array[object]

      Column headings for the search results. Each object is a column.

      details#setActive"> Hide columns attributes Show columns attributes object
      • name string Required
      • type string Required
    • cursor string

      The cursor for the next set of paginated results. For CSV, TSV, and TXT responses, this value is returned in the Cursor HTTP header.

    • id string
    • is_running boolean

      If true, the search is still running. If false, the search has finished. This value is returned only for async and saved synchronous searches. For CSV, TSV, and TXT responses, this value is returned in the Async-partial HTTP header.

    • is_partial boolean

      If true, the response does not contain complete search results. If is_partial is true and is_running is true, the search is still running. If is_partial is true but is_running is false, the results are partial due to a failure or timeout. This value is returned only for async and saved synchronous searches. For CSV, TSV, and TXT responses, this value is returned in the Async-partial HTTP header.

    • rows array[array] Required

      The values for the search results.

POST _sql?format=txt
{
  "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
}
resp = client.sql.query(
    format="txt",
    query="SELECT * FROM library ORDER BY page_count DESC LIMIT 5",
)
const response = await client.sql.query({
  format: "txt",
  query: "SELECT * FROM library ORDER BY page_count DESC LIMIT 5",
});
response = client.sql.query(
  format: "txt",
  body: {
    "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
  }
)
$resp = $client->sql()->query([
    "format" => "txt",
    "body" => [
        "query" => "SELECT * FROM library ORDER BY page_count DESC LIMIT 5",
    ],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"query":"SELECT * FROM library ORDER BY page_count DESC LIMIT 5"}' "$ELASTICSEARCH_URL/_sql?format=txt"
client.sql().query(q -> q
    .format(SqlFormat.Txt)
    .query("SELECT * FROM library ORDER BY page_count DESC LIMIT 5")
);
Request example
Run `POST _sql?format=txt` to get results for an SQL search.
{
  "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
}