[BUG] Request-level filter is ignored for aggregation queries (`COUNT`) but applied for regular `SELECT`
I maintainer di solito rispondono entro 1 giorno
@RyanL1997 ci sta già lavorando.
Dal 28/7/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Request-level filter is ignored for aggregation queries (COUNT) but applied for regular SELECT
Description
The SQL REST API request-level filter is correctly applied for regular SELECT queries, but it is ignored for aggregation queries such as COUNT(*).
The generated DSL (/_plugins/_sql/_explain) shows that the request filter disappears when the query contains an aggregation.
Environment
| Component | Version |
|---|---|
| OpenSearch | 3.6.0 |
| SQL Plugin | 3.6.0.0 |
Expected behavior
The request-level filter should always be merged with the SQL query, regardless of whether the SQL query contains aggregations.
The generated DSL should contain:
- predicates generated from the SQL
WHEREclause - predicates supplied in the request
filter
Actual behavior
For regular SELECT queries, the request filter is correctly merged into the generated OpenSearch query.
For aggregation queries (COUNT(*)), the request filter is missing from the generated DSL and therefore has no effect on the result.
Reproduction
1. Aggregation query
POST /_plugins/_sql?format=jdbc
{
"filter": {
"bool": {
"must": [
{
"query_string": {
"query": "(document.type.keyword: \"IE415B\")"
}
}
]
}
},
"parameters": [
{
"type": "keyword",
"value": "SearchSqlIT"
}
],
"query": "SELECT COUNT(*) AS c FROM test.app.sample1 WHERE document.name = ?"
}
Result:
{
"schema": [
{
"name": "c",
"alias": "c",
"type": "double"
}
],
"datarows": [
[
20
]
]
}
Expected result:
5
2. Explain output
POST /_plugins/_sql/_explain
{
"filter": {
"bool": {
"must": [
{
"query_string": {
"query": "(document.type.keyword: \"IE415B\")"
}
}
]
}
},
"parameters": [
{
"type": "keyword",
"value": "SearchSqlIT"
}
],
"query": "SELECT COUNT(*) AS c FROM test.app.sample1 WHERE document.name = ?"
}
Generated DSL:
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"document.name.keyword": {
"value": "SearchSqlIT"
}
}
}
]
}
}
]
}
},
"aggregations": {
"c": {
"value_count": {
"field": "_index"
}
}
}
}
Notice that the request-level filter
{
"query_string": {
"query": "(document.type.keyword: \"IE415B\")"
}
}
is completely missing.
3. Regular SELECT
POST /_plugins/_sql/_explain
{
"filter": {
"bool": {
"must": [
{
"query_string": {
"query": "(document.type.keyword: \"IE415B\")"
}
}
]
}
},
"parameters": [
{
"type": "keyword",
"value": "SearchSqlIT"
}
],
"query": "SELECT * FROM test.app.sample1 WHERE document.name = ?"
}
Generated DSL correctly contains both
- SQL predicate
- request-level filter
{
"from": 0,
"size": 200,
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"document.name.keyword": {
"value": "SearchSqlIT",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"filter": [
{
"bool": {
"must": [
{
"query_string": {
"query": """(document.type.keyword: "IE415B")""",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
which demonstrates that request filtering works correctly for non-aggregation queries.
Verification
The following SQL query returns the expected result:
SELECT COUNT(*)
FROM test.app.sample1
WHERE document.name = ?
AND document.type = 'IE415B'
Result:
5
Therefore the request-level filter should produce the same result, but it instead returns:
20
Conclusion
It appears that the request-level filter is ignored during SQL planning for aggregation queries.
The problem is already visible in the output of /_plugins/_sql/_explain, indicating that the request filter is dropped before the OpenSearch query is executed.
This behavior is inconsistent with regular SELECT queries, where the request filter is correctly merged into the generated DSL.
- Lingua principale
- Java
- Stelle
- 175
- Fork
- 233
- Merge medio
- 2g 16h
- PR unite (30g)
- 39
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di opensearch-project/sql
-
[Enhancement] Make the flat_object read depth cap configurable instead of a constantForse già presa @RyanL1997 l’ha presa 13 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
opensearch-project/sql#5842 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Forse già presa @nagendramohan l’ha presa 76 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
opensearch-project/sql#5684 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[DOC] Calcite settings documentation missing examplesForse già presa @AzazelSensei l’ha presa 33 giorni fa. Apertadocumentation PPL
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/sql#4806 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement untriaged
Difficoltà 4/5 3-5 giorni Idoneità per principianti 54/100
opensearch-project/sql#5906 ·
I maintainer di solito rispondono entro 1 giorno
-
bug PPL untriaged
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
opensearch-project/sql#5904 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di opensearch-project/sql
Issue simili
-
[BUG] jackson3 JacksonJsonpMapper(ObjectMapper) fails to deserialize `_source` with "Trailing token" errorForse già presa @junyeokk l’ha presa oggi. Apertabug untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/opensearch-java#2236 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
open-learning-exchange/myplanet#18392 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
linagora/twake-calendar-side-service#1218 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] [Go] Ack returns nil when the server answers with a non-OK statusForse già presa @leizhiyuan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/rocketmq-clients#1465 ·
I maintainer di solito rispondono entro 2 giorni