Table of contents
To send query request to SQL plugin, you MUST use HTTP POST request. POST request doesn't have length limitation and allows for other parameters passed to plugin for other functionality such as prepared statement. And also the explain endpoint is used very often for query translation and troubleshooting.
You can also send HTTP POST request with your query in request body.
SQL query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql -d '{
"query" : "SELECT * FROM accounts"
}'To translate your query, send it to explain endpoint. The explain output is OpenSearch domain specific language (DSL) in JSON format. You can just copy and paste it to your console to run it against OpenSearch directly.
For queries which run with Calcite engine (V3), explain output could be set different formats: standard (the default format), simple and extended.
Explain query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql/_explain -d '{
"query" : "SELECT firstname, lastname FROM accounts WHERE age > 20"
}'Explain:
{
"from" : 0,
"size" : 200,
"query" : {
"bool" : {
"filter" : [
{
"bool" : {
"must" : [
{
"range" : {
"age" : {
"from" : 20,
"to" : null,
"include_lower" : false,
"include_upper" : true,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"_source" : {
"includes" : [
"firstname",
"lastname"
]
}
}To enable Calcite engine, set plugins.calcite.enabled to true.
Explain query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql/_explain -d '{
"query" : "source = state_country | where country = 'USA' OR country = 'England' | stats count() by country"
}'Explain:
{
"calcite": {
"logical": """LogicalProject(count()=[$1], country=[$0])
LogicalAggregate(group=[{1}], count()=[COUNT()])
LogicalFilter(condition=[SEARCH($1, Sarg['England', 'USA':CHAR(7)]:CHAR(7))])
CalciteLogicalIndexScan(table=[[OpenSearch, state_country]])
""",
"physical": """EnumerableCalc(expr#0..1=[{inputs}], count()=[$t1], country=[$t0])
CalciteEnumerableIndexScan(table=[[OpenSearch, state_country]], PushDownContext=[[FILTER->SEARCH($1, Sarg['England', 'USA':CHAR(7)]:CHAR(7)), AGGREGATION->rel#57:LogicalAggregate.NONE.[](input=RelSubset#47,group={1},count()=COUNT())], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":0,"timeout":"1m","query":{"terms":{"country":["England","USA"],"boost":1.0}},"aggregations":{"composite_buckets":{"composite":{"size":1000,"sources":[{"country":{"terms":{"field":"country","missing_bucket":true,"missing_order":"first","order":"asc"}}}]},"aggregations":{"count()":{"value_count":{"field":"_index"}}}}}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])
"""
}
}To enable Calcite engine, set plugins.calcite.enabled to true.
Explain query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql/_explain?format=simple -d '{
"query" : "source = state_country | where country = 'USA' OR country = 'England' | stats count() by country"
}'Explain:
{
"calcite": {
"logical": """LogicalProject
LogicalAggregate
LogicalFilter
CalciteLogicalIndexScan
"""
}
}To enable Calcite engine, set plugins.calcite.enabled to true.
Explain query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql/_explain?format=extended -d '{
"query" : "source = state_country | where country = 'USA' OR country = 'England' | stats count() by country"
}'Explain:
{
"calcite": {
"logical": """LogicalProject(count()=[$1], country=[$0])
LogicalAggregate(group=[{1}], count()=[COUNT()])
LogicalFilter(condition=[SEARCH($1, Sarg['England', 'USA':CHAR(7)]:CHAR(7))])
CalciteLogicalIndexScan(table=[[OpenSearch, state_country]])
""",
"physical": """EnumerableCalc(expr#0..1=[{inputs}], count()=[$t1], country=[$t0])
CalciteEnumerableIndexScan(table=[[OpenSearch, state_country]], PushDownContext=[[FILTER->SEARCH($1, Sarg['England', 'USA':CHAR(7)]:CHAR(7)), AGGREGATION->rel#125:LogicalAggregate.NONE.[](input=RelSubset#115,group={1},count()=COUNT())], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":0,"timeout":"1m","query":{"terms":{"country":["England","USA"],"boost":1.0}},"aggregations":{"composite_buckets":{"composite":{"size":1000,"sources":[{"country":{"terms":{"field":"country","missing_bucket":true,"missing_order":"first","order":"asc"}}}]},"aggregations":{"count()":{"value_count":{"field":"_index"}}}}}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])
""",
"extended": """public org.apache.calcite.linq4j.Enumerable bind(final org.apache.calcite.DataContext root) {
final org.opensearch.sql.opensearch.storage.scan.CalciteEnumerableIndexScan v1stashed = (org.opensearch.sql.opensearch.storage.scan.CalciteEnumerableIndexScan) root.get("v1stashed");
final org.apache.calcite.linq4j.Enumerable _inputEnumerable = v1stashed.scan();
return new org.apache.calcite.linq4j.AbstractEnumerable(){
public org.apache.calcite.linq4j.Enumerator enumerator() {
return new org.apache.calcite.linq4j.Enumerator(){
public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable.enumerator();
public void reset() {
inputEnumerator.reset();
}
public boolean moveNext() {
return inputEnumerator.moveNext();
}
public void close() {
inputEnumerator.close();
}
public Object current() {
final Object[] current = (Object[]) inputEnumerator.current();
final Object input_value = current[1];
final Object input_value0 = current[0];
return new Object[] {
input_value,
input_value0};
}
};
}
};
}
public Class getElementType() {
return java.lang.Object[].class;
}
"""
}
}To get paginated response for a SQL query, user needs to provide fetch_size parameter as part of normal query. The value of fetch_size should be greater than 0. In absence of fetch_size or a value of 0, it will fallback to non-paginated response. This feature is only available over jdbc format for now.
SQL query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql -d '{
"fetch_size" : 5,
"query" : "SELECT firstname, lastname FROM accounts WHERE age > 20 ORDER BY state ASC"
}'Result set:
{
"schema": [
{
"name": "firstname",
"type": "text"
},
{
"name": "lastname",
"type": "text"
}
],
"cursor": "d:eyJhIjp7fSwicyI6IkRYRjFaWEo1UVc1a1JtVjBZMmdCQUFBQUFBQUFBQU1XZWpkdFRFRkZUMlpTZEZkeFdsWnJkRlZoYnpaeVVRPT0iLCJjIjpbeyJuYW1lIjoiZmlyc3RuYW1lIiwidHlwZSI6InRleHQifSx7Im5hbWUiOiJsYXN0bmFtZSIsInR5cGUiOiJ0ZXh0In1dLCJmIjo1LCJpIjoiYWNjb3VudHMiLCJsIjo5NTF9",
"total": 956,
"datarows": [
[
"Cherry",
"Carey"
],
[
"Lindsey",
"Hawkins"
],
[
"Sargent",
"Powers"
],
[
"Campos",
"Olsen"
],
[
"Savannah",
"Kirby"
]
],
"size": 5,
"status": 200
}Profiling captures per-stage timings (in milliseconds) for SQL query
execution. To enable profiling, set "profile": true in the request
body alongside "query".
Note
The profile parameter only takes effect when the query runs on
the Analytics Engine. In all other cases the flag is silently ignored.
Profile output is returned only for regular query execution (not
_explain) and only with the default format=jdbc.
Request:
POST /_plugins/_sql
{
"query": "SELECT customer_id, SUM(amount) FROM orders GROUP BY customer_id",
"profile": true
}Expected output (trimmed):
{
"profile": {
"summary": {
"total_time_ms": 33.34
},
"phases": {
"analyze": { "time_ms": 8.68 },
"optimize": { "time_ms": 18.2 },
"execute": { "time_ms": 4.87 },
"format": { "time_ms": 0.05 }
},
"plan": {
"node": "EnumerableCalc",
"time_ms": 4.82,
"rows": 2,
"children": [
{ "node": "CalciteEnumerableIndexScan", "time_ms": 4.12, "rows": 2 }
]
}
}
}start_time and end_time tell the engine which time window a request is asking about, and time_field names the field they constrain. When plugins.query.pruning.enabled is on, a query over a wildcard index expression then reads only the indices that can hold data in that window, rather than all of them.
The bounds take effect whether or not the query filters on time. What a matching filter decides is whether the answer changes: with an equivalent where clause on the same field and range, the result is identical to the same query without the bounds, because every index dropped is one the clause already excluded. Without it rows go missing, since the bounds exclude whole indices and nothing else filtered them. Send them only for a window the query itself restricts.
They apply to the outermost source= only. A join's other side, a subsearch's source, a multisearch dataset and a lookup's dimension table are left alone, since the query's own time filter is not known to constrain them.
Both bounds are required and both are inclusive. time_field defaults to @timestamp, so an index pattern whose time field is named something else has to give it. Accepted literals:
| Literal | Example |
|---|---|
| OpenSearch date math | now, now-7d, now-1d/d |
| ISO-8601 date and time, zone optional | 2026-02-01T00:00:00.000Z, 2026-02-01T00:00:00 |
| ISO-8601 date only | 2026-02-01 |
| Epoch milliseconds | 1769904000000 |
| Date and time separated by a space | 2026-02-01 00:00:00.000, 2026-02-01 00:00:00 |
Epoch seconds are not accepted; a ten-digit number is read as milliseconds. A value that cannot be used is ignored rather than failing the request, and nothing is pruned. See plugins.query.pruning.enabled for the setting and its limitations.
Two monthly indices, logs-2026.01 and logs-2026.02. The bounds repeat the window the where clause already restricts, so only February is read:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_ppl -d '{
"query" : "source=logs-* | where `@timestamp` >= \"2026-02-01 00:00:00\" and `@timestamp` <= \"2026-02-28 23:59:59\" | stats count() as requests",
"time_field" : "@timestamp",
"start_time" : "2026-02-01 00:00:00",
"end_time" : "2026-02-28 23:59:59"
}'Result set:
{
"schema": [
{
"name": "requests",
"type": "bigint"
}
],
"datarows": [
[
1
]
],
"total": 1,
"size": 1
}The same query without the bounds returns the same row, having read both indices.
The fetch_size parameter limits the number of rows returned in a PPL query response. The value of fetch_size should be greater than 0. In absence of fetch_size or a value of 0, the result size is governed by the plugins.query.size_limit cluster setting.
fetch_size can be specified either as a URL parameter or in the JSON request body. If both are provided, the JSON body value takes precedence.
If fetch_size is larger than plugins.query.size_limit, the result is capped at plugins.query.size_limit. The effective number of rows returned is always min(fetch_size, plugins.query.size_limit).
Unlike SQL's fetch_size which enables cursor-based pagination, PPL's fetch_size does not return a cursor and does not support fetching additional pages. The response is always complete and final.
| Aspect | SQL fetch_size |
PPL fetch_size |
|---|---|---|
| Purpose | Cursor-based pagination | Response size limiting |
| Returns cursor? | Yes | No |
| Can fetch more? | Yes (with cursor) | No (single response) |
PPL query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_ppl -d '{
"fetch_size" : 5,
"query" : "source = accounts | fields firstname, lastname | where age > 20"
}'PPL query:
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_ppl?fetch_size=5 -d '{
"query" : "source = accounts | fields firstname, lastname | where age > 20"
}'Result set:
{
"schema": [
{
"name": "firstname",
"type": "text"
},
{
"name": "lastname",
"type": "text"
}
],
"total": 5,
"datarows": [
["Cherry", "Carey"],
["Lindsey", "Hawkins"],
["Sargent", "Powers"],
["Campos", "Olsen"],
["Savannah", "Kirby"]
],
"size": 5,
"status": 200
}