[BUG] sort returns 500 when a field is keyword or ip in one index and a number, date or boolean in another
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Reproduce the failure with the provided curl commands, then read SearchPhaseController.createSort and AbstractCalciteIndexScan.pushDownSort to trace how mixed field types reach the sort. Check OpenSearchDescribeIndexRequest.getFieldTypes and BackgroundSearchScanner.getCurrentResponse for the type information and error propagation. Done means mixed keyword and numeric/date fields no longer produce an uninformative HTTP 500.
由索引模型根据 Issue 内容生成。
描述
Query Information
PPL Command/Query:
source=logs_* | sort f | fields host
f is keyword in logs_a and long in logs_b, which is what a rollover mapping change leaves behind.
Expected Result: both documents sorted by f, or a 400 naming the conflicting types.
Actual Result: HTTP 500, and details does not name the cause.
{
"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 over the same indices. Adding ?error_trace=true to that search gives the stack below.
java.lang.ClassCastException: class java.lang.Long 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.action.search.SearchPhaseController.mergeTopDocs(SearchPhaseController.java:240)
at org.opensearch.action.search.SearchPhaseController.sortDocs(SearchPhaseController.java:187)
at org.opensearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:534)
at org.opensearch.action.search.QueryPhaseResultConsumer.reduce(QueryPhaseResultConsumer.java:187)
Every command that pushes a sort on f returns 500 when one side is keyword or ip and the other a number, date or boolean. The first two sort by term bytes and the others sort numerically.
f in one index |
f in the other |
merged type of f |
sort f |
sort - f |
sort f | reverse |
sort f | head 1 |
self join on f |
|---|---|---|---|---|---|---|---|
keyword |
byte |
string or tinyint |
500 | 500 | 500 | 500 | 500 |
keyword |
integer |
int or string |
500 | 500 | 500 | 500 | 500 |
keyword |
long |
string or bigint |
500 | 500 | 500 | 500 | 500 |
keyword |
date |
timestamp or string |
500 | 500 | 500 | 500 | 500 |
keyword |
boolean |
string or boolean |
500 | 500 | 500 | 500 | 500 |
ip |
long |
ip or bigint |
500 | 500 | 500 | 500 | 500 |
ip |
date |
ip or timestamp |
500 | 500 | 500 | 500 | 500 |
ip |
boolean |
ip or boolean |
500 | 500 | 500 | 500 | 500 |
keyword |
text |
string |
200 | 200 | 200 | 200 | 200 |
byte |
integer |
tinyint or int |
200 | 200 | 200 | 200 | 200 |
byte |
long |
tinyint or bigint |
200 | 200 | 200 | 200 | 200 |
integer |
long |
int or bigint |
200 | 200 | 200 | 200 | 200 |
byte |
date |
tinyint or timestamp |
200 | 200 | 200 | 200 | 200, 1 or 2 of 2 rows |
integer |
date |
int or timestamp |
200 | 200 | 200 | 200 | 200, 1 or 2 of 2 rows |
long |
date |
bigint or timestamp |
200 | 200 | 200 | 200 | 200, 1 or 2 of 2 rows |
The merged type is whichever index the mapping merge reads last, see #5752. It differed between runs on the same node, and a cell shows both types where it did. Every failing pair failed under every merged type seen, so the failure does not depend on which type wins. A boolean field fails only against keyword or ip, with java.lang.Integer in place of java.lang.Long in the ClassCastException. join fails because each side of the EnumerableMergeJoin pushes its own sort on f, with a SearchPhaseExecutionException whose reason is Error occurred in OpenSearch engine: and nothing after the colon.
Other pairs of the same sort kind also return 200, such as boolean against a number or date, and long against double. The join cells marked 1 or 2 of 2 are a separate defect. Under a numeric merged type the date document's f reads as null, so that document cannot join to itself.
One more pair returns 200 with a wrong result, and it reproduces with a raw _search and no plugin. keyword against ip merges one page correctly but not the next. A search_after past the keyword value a fails on the ip shard with 'a' is not an IP string literal., and that shard is dropped from the 200, so the second page returns 2 rows where 5 remain.
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": "long" } } } }
Sample Data
POST logs_a/_doc/1?refresh=true { "host": "a", "f": "300" }
POST logs_b/_doc/1?refresh=true { "host": "b", "f": 5 }
Each index alone sorts fine, and source=logs_* | fields host, f returns 200, so the merge is not what fails.
Bug Description
Issue Summary
OpenSearch core cannot merge sorted hits across shards when the sort field sorts by term bytes on one shard, as keyword and ip do, and numerically on another, as numbers, date and boolean do. SearchPhaseController.createSort takes the first shard's SortField and widens it only when every shard is numeric, and its own TODO: should we check the compatibility between types marks the gap. With a term shard in the mix, TermOrdValComparator receives a Long or an Integer and throws. A raw _search with "sort":[{"f":"asc"}] over the same two indices returns the same 500 without the plugin.
PPL pushes the sort into that request without checking that f has one type across the indices. AbstractCalciteIndexScan.pushDownSort guards only binary fields, at line 397, and then emits a bare fieldSort(f). The per-index types that would reveal the conflict are already gone by then. OpenSearchDescribeIndexRequest.getFieldTypes merges them into one map and keeps only the result, next to its own TODO possible collision if two indices have fields with the same name and different mappings.
details does not name the cause because the core exception carries an empty message, visible as "reason": "" on the raw search. BackgroundSearchScanner.getCurrentResponse builds the PPL error from e.getMessage() at line 141, and that text stops at Failed to execute phase [fetch], . The ClassCastException survives only in the Java cause chain, wrapped in turn by ExecutionException, NonFallbackCalciteException, SQLException and RuntimeException, so a user sees neither the field nor the types.
Pushdown off returns both rows in order
The same query with plugins.calcite.pushdown.enabled=false returns HTTP 200.
{
"schema": [
{
"name": "host",
"type": "string"
}
],
"datarows": [
[
"b"
],
[
"a"
]
],
"total": 2,
"size": 2
}
With pushdown off the sort runs in memory over the merged f, which was bigint on this run, so b with 5 sorts ahead of a with 300. Adding f to the projection returns ["b", 5] then ["a", 300] with f typed bigint.
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":"long"}}}}'
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":5}'
# 1. Returns HTTP 500
curl -s -XPOST "localhost:9200/_plugins/_ppl" -H 'Content-Type: application/json' \
-d '{"query":"source=logs_* | sort f | fields host"}' -w '\nHTTP %{http_code}\n'
# 2. The same sort as a raw search, no plugin, also returns 500 with the ClassCastException
curl -s -XPOST "localhost:9200/logs_*/_search?error_trace=true" -H 'Content-Type: application/json' \
-d '{"sort":[{"f":"asc"}]}' -w '\nHTTP %{http_code}\n'
# 3. With pushdown off, query 1 returns 200 with both rows
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_* | sort f | fields host"}' -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
In an index-pattern deployment, one rolled-over index that maps a field as a number, date or boolean where older indices map it as keyword or ip breaks every sort on that field. That includes head after sort and join on the field, with a 500 that names neither the field nor the conflict.
Environment Information
OpenSearch Version: main at 67aed0ee8, 3.10.0-SNAPSHOT, one node, with the defaults plugins.calcite.enabled=true, plugins.calcite.pushdown.enabled=true and plugins.calcite.fallback.allowed=false.
Additional Details:
- #5811 is the same kind of conflict in composite aggregation, through
stats ... by,topanddedup. - A
textfield against any other type can fail silently. When the other type wins the merge, as withinteger,long,dateorip, PPL pushes the sort, it fails on thetextshard becausetexthas no fielddata, and OpenSearch drops that shard from the result. Every command in the table then returns 200 with only the other index's row. Whentextwins, PPL does not push the sort and both rows come back. With pushdown off both rows always come back.
- 主要语言
- 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 ·