[BUG] Request-level filter is ignored for aggregation queries (`COUNT`) but applied for regular `SELECT`
Los mantenedores suelen responder en 1 día
@RyanL1997 ya está trabajando en esto.
Desde el 28/7/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 175
- Forks
- 236
- Merge medio
- 2 d 15 h
- PR fusionados (30 d)
- 41
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de opensearch-project/sql
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Posiblemente ocupada @nagendramohan la tomó hace 87 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
opensearch-project/sql#5684 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
[DOC] Calcite settings documentation missing examplesPosiblemente ocupada @AzazelSensei la tomó hace 44 días. Abiertodocumentation PPL
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
opensearch-project/sql#4806 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
opensearch-project/sql#5928 ·
Los mantenedores suelen responder en 1 día
-
[Testing] Test downstream plugins that load SQL classes (alerting, skills)Posiblemente ocupada @ahkcs la tomó hace 2 días. Abiertoinfrastructure testing
Dificultad 5/5 Más de una semana Aptitud para principiantes 18/100
opensearch-project/sql#5925 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[BUG] Analytics routing does not resolve aliases and wildcard index expressionsPosiblemente ocupada @KarstenSchnitter la tomó hace 7 días. Abiertoanalytic-engine bug
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
opensearch-project/sql#5916 ·
Los mantenedores suelen responder en 1 día
Todos los issues de opensearch-project/sql
Issues similares
-
hermes-queue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
chrisalunlloyd2-sudo/mindpalace#337 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ucsb-cs156/proj-frontiers#844 ·
-
Update spring-ldap to 4.0.7Abiertotype: dependency-upgrade
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
spring-projects/spring-security#20057 ·
Los mantenedores suelen responder en 1 día
-
Spark benchmarks crash with `[INVALID_DRIVER_MEMORY]` on JVMs whose default heap is below Spark's ~450 MB minimumPosiblemente ocupada @sendaoYan la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
moquette-io/moquette#980 ·