[BUG] stats max and stats min return 500 when a field is keyword or ip and boolean or a number in another
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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時間
- マージ済み PR(30日)
- 34
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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 ·