[BUG] stats max and stats min return 500 when a field is keyword or ip and boolean or a number in another
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by reproducing the supplied logs_a/logs_b mappings and stats max(f) and stats min(f) queries through the /_plugins/_ppl endpoint; compare with pushdown disabled. Then read the top_hits pushdown for non-numeric max and min introduced in #4281 and trace how the merged field type affects the aggregation. Done means mixed mappings no longer produce an uninformative HTTP 500: the query returns a valid maximum or minimum, or a 400 that identifies the conflicting types.
由索引模型根据 Issue 内容生成。
描述
Query Information
PPL Command/Query:
source=logs_* | stats max(f)
f is keyword in logs_a and boolean in logs_b, which is what a rollover mapping change leaves behind.
Expected Result: the maximum over both indices, or a 400 naming the conflicting types.
Actual Result: HTTP 500, and details does not name the cause. stats min(f) fails the same way.
{
"error": {
"context": {
"stage": "executing",
"stage_description": "Running the query"
},
"reason": "java.sql.SQLException: exception while executing query: Failed to fetch data from the index: the background task failed or interrupted.\n Inner error: Failed to execute phase [fetch], ",
"details": "java.sql.SQLException: exception while executing query: Failed to fetch data from the index: the background task failed or interrupted.\n Inner error: Failed to execute phase [fetch], ",
"location": ["while running the query"],
"code": "UNKNOWN",
"type": "RuntimeException"
},
"status": 500
}
The cause shows up in the node log and in caused_by.reason on a raw _search that sends the DSL from _explain to logs_*. Adding ?error_trace=true to that search gives the stack below.
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class org.apache.lucene.util.BytesRef
at org.apache.lucene.search.comparators.TermOrdValComparator.compareValues(TermOrdValComparator.java:53)
...
at org.apache.lucene.search.TopDocs.merge(TopDocs.java:261)
at org.opensearch.search.aggregations.metrics.InternalTopHits.reduce(InternalTopHits.java:150)
at org.opensearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:188)
at org.opensearch.search.aggregations.InternalAggregations.topLevelReduce(InternalAggregations.java:135)
at org.opensearch.action.search.SearchPhaseController.reduceAggs(SearchPhaseController.java:561)
Dataset Information
Dataset/Schema Type
- OpenTelemetry (OTEL)
- Simple Schema for Observability (SS4O)
- Open Cybersecurity Schema Framework (OCSF)
- Custom (details below)
Index Mapping
PUT logs_a { "mappings": { "properties": { "host": { "type": "keyword" }, "f": { "type": "keyword" } } } }
PUT logs_b { "mappings": { "properties": { "host": { "type": "keyword" }, "f": { "type": "boolean" } } } }
Sample Data
POST logs_a/_doc/1?refresh=true { "host": "a", "f": "300" }
POST logs_b/_doc/1?refresh=true { "host": "b", "f": true }
Bug Description
Issue Summary:
PPL pushes max and min on a field that is not a number or date type, such as string, ip or boolean, as a top_hits of size 1 sorted on f. Over a wildcard, PPL picks between the native aggregation and top_hits from the merged type of f, while each shard sorts f by its own mapping. A keyword or ip shard returns a BytesRef sort value, and a boolean shard returns an Integer. InternalTopHits.reduce merges them with one Lucene comparator, which throws a ClassCastException.
Each index alone returns 200. The merged type is whichever index the mapping merge reads last, see #5752. It changes with the index names, so every pair below ran under 10 different name prefixes on fresh indices. In the last column both indices hold a document with host set to s, and the query is where host = 's' | stats max(f) by host.
f in one index |
f in the other |
merged type | stats max(f) |
stats min(f) |
stats max(f) by host, one host in both indices |
|---|---|---|---|---|---|
keyword |
boolean |
boolean |
500 | 500 | 500 |
keyword |
boolean |
string |
500 | 500 | 500 |
ip |
boolean |
boolean |
500 | 500 | 500 |
ip |
boolean |
ip |
500 | 500 | 500 |
keyword |
long |
string |
500 | 500 | 500 |
keyword |
long |
bigint |
200, "300" dropped |
200, "300" dropped |
200, "300" dropped |
ip |
long |
ip |
500 | 500 | 500 |
boolean |
long |
boolean |
500 | 500 | 500 |
keyword |
ip |
string or ip |
200, wrong for some values | 200, wrong for some values | 200, wrong for some values |
integer |
long |
int or bigint |
200 | 200 | 200 |
The values were "300" for keyword, 5 for the integer types, true for boolean and 10.0.0.1 for ip.
Every 500 in the table is this bug. The keyword and boolean pair and the ip and boolean pair fail under both merged types. The other failing pairs fail only when the merged type is string, ip or boolean, because a numeric or date merged type pushes a native max or min with no sort to merge. keyword against ip never fails, since both sides sort as BytesRef. The 200 cells marked wrong or dropped are other defects, and the dropped value is #5687.
With plugins.calcite.pushdown.enabled set to false, the same query returns 200, since no top_hits reaches OpenSearch. With Calcite off, the v2 engine rejects both functions on logs_* under boolean with a 400.
#5825 is the same TopDocs.merge failure reached through a pushed sort, with the top-level SearchPhaseController.sortDocs in place of InternalTopHits.reduce. The sort here sits inside an aggregation, so it does not go through the sort pushdown that #5825 covers.
Steps to Reproduce:
curl -s -XPUT "localhost:9200/logs_a" -H 'Content-Type: application/json' \
-d '{"mappings":{"properties":{"host":{"type":"keyword"},"f":{"type":"keyword"}}}}'
curl -s -XPUT "localhost:9200/logs_b" -H 'Content-Type: application/json' \
-d '{"mappings":{"properties":{"host":{"type":"keyword"},"f":{"type":"boolean"}}}}'
curl -s -XPOST "localhost:9200/logs_a/_doc/1?refresh=true" -H 'Content-Type: application/json' -d '{"host":"a","f":"300"}'
curl -s -XPOST "localhost:9200/logs_b/_doc/1?refresh=true" -H 'Content-Type: application/json' -d '{"host":"b","f":true}'
# 1. Returns HTTP 500, whichever type the merge picks for f
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_* | stats max(f)"}' -w '\nHTTP %{http_code}\n'
# 2. stats min returns the same 500
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_* | stats min(f)"}' -w '\nHTTP %{http_code}\n'
# 3. Each index alone returns 200
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_a | stats max(f)"}' -w '\nHTTP %{http_code}\n'
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_b | stats max(f)"}' -w '\nHTTP %{http_code}\n'
# 4. A top_hits sorted on f, the shape PPL pushes, sent as a raw search with no plugin,
# also returns 500, with the ClassCastException in caused_by
curl -s -XPOST "localhost:9200/logs_*/_search?error_trace=true" -H 'Content-Type: application/json' \
-d '{"size":0,"aggs":{"m":{"top_hits":{"size":1,"sort":[{"f":{"order":"desc"}}]}}}}' -w '\nHTTP %{http_code}\n'
# 5. With pushdown off, queries 1 and 2 return 200
curl -s -XPUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' \
-d '{"transient":{"plugins.calcite.pushdown.enabled":false}}'
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_* | stats max(f)"}' -w '\nHTTP %{http_code}\n'
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_* | stats min(f)"}' -w '\nHTTP %{http_code}\n'
# Restore the default
curl -s -XPUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' \
-d '{"transient":{"plugins.calcite.pushdown.enabled":null}}'
Impact:
After a rollover changes the mapping of a field, stats max and stats min on that field over the data stream or its wildcard return 500, and the response does not say which field or which types conflict.
Environment Information
OpenSearch Version: main at 803ed31c8, 3.10.0-SNAPSHOT, one node, one shard per index. plugins.calcite.enabled is true, plugins.calcite.pushdown.enabled is true and plugins.calcite.fallback.allowed is false.
Additional Details:
- #4281 introduced the
top_hitspushdown formaxandminon non-numeric fields.
- 主要语言
- Java
- 星标
- 176
- 派生
- 237
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 34
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
opensearch-project/sql 的其他 Issue
-
bug untriaged
难度 2/5 1-3 小时 新手友好度 78/100
opensearch-project/sql#5990 ·
维护者通常 1 天内回复
-
bug untriaged
难度 1/5 1 小时以内 新手友好度 85/100
opensearch-project/sql#5983 ·
维护者通常 1 天内回复
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"可能已有人在做 @nagendramohan 于 107 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
opensearch-project/sql#5684 · 4 条评论 ·
维护者通常 1 天内回复
-
[DOC] Calcite settings documentation missing examples可能已有人在做 @AzazelSensei 于 64 天前认领。 未关闭documentation PPL
难度 2/5 1-3 小时 新手友好度 72/100
opensearch-project/sql#4806 · 1 条评论 ·
维护者通常 1 天内回复
-
calcite enhancement Meta performance PPL untriaged
难度 5/5 一周以上 新手友好度 8/100
opensearch-project/sql#5991 ·
维护者通常 1 天内回复
查看 opensearch-project/sql 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
PCL-Community/PCL-CE#3907 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 2 天内回复
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
docker-to-squash.py: check_dependencies should find mksquashfs on PATH可能已有人在做 @linzch3 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
chore
难度 1/5 1-3 小时 新手友好度 88/100
lugassawan/swe-workbench#841 ·