Skip to content

Elasticsearch8.15.0 Group By 聚合操作,Elasticsearch 返回数据顺序不一致,JDBC方式返回数据直接错乱 #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FJGeGe opened this issue Apr 10, 2025 · 1 comment

Comments

@FJGeGe
Copy link

FJGeGe commented Apr 10, 2025

1、请求sql:
select 终端类型,sum(订单数) 充电次数,sum(充电量) 充电电量,sum(运营时长) 运营时长 from xxx where 业务日期>='20250408+08:00' and 终端编号='1290833701' group by 终端类型 limit 10
2、上述中的DSL:
{ "from": 0, "size": 0, "query": { "bool": { "filter": [ { "bool": { "must": [ { "bool": { "must": [ { "range": { "业务日期": { "gte": "20250408+08:00", "boost": 1.0 } } }, { "match_phrase": { "终端编号": { "query": "1290833701" } } } ], "boost": 1.0 } } ], "boost": 1.0 } } ], "boost": 1.0 } }, "_source": { "includes": [ "终端类型", "sum", "sum", "sum" ], "excludes": [] }, "stored_fields": "终端类型", "aggregations": { "终端类型": { "terms": { "field": "终端类型", "size": 10, "shard_size": 5000, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": [ { "_count": "desc" }, { "_key": "asc" } ] }, "aggregations": { "充电次数": { "sum": { "field": "订单数" } }, "充电电量": { "sum": { "field": "充电量" } }, "运营时长": { "sum": { "field": "运营时长" } } } } } }

3、ES返回结果:
{ "took": 28, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 3, "relation": "eq" }, "max_score": null, "hits": [] }, "aggregations": { "终端类型": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "AC single-phase", "doc_count": 2, "运营时长": { "value": 2880.0 }, "充电电量": { "value": 0.0 }, "充电次数": { "value": 0.0 } }, { "key": "AC three-phase", "doc_count": 1, "充电次数": { "value": 0.0 }, "充电电量": { "value": 0.0 }, "运营时长": { "value": 1440.0 } } ] } } }

4、获取最终结果错位:
[{"终端类型":"AC single-phase","运营时长":"2880.0","充电电量":"0.0","充电次数":"0.0"},{"终端类型":"AC three-phase","运营时长":"0.0","充电电量":"0.0","充电次数":"1440.0"}]

5、代码追踪:

ObjectResultsExtractor 类: ![Image](https://github.com/user-attachments/assets/43e54ccc-d377-400a-8f35-7cfdbf9afd96)

@FJGeGe
Copy link
Author

FJGeGe commented Apr 10, 2025

目前更改办法:
`

Image

Image

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant