es版本7.9
存储的数据格式如下:
{
"_index": "properties_trsq_rhqsqsq_2021-11",
"_type": "_doc",
"_id": "3cae2cb0be59a5b44af5eb7d5ce945dd",
"_score": 1.0,
"_source": {
"productId": "trsq_rhqsqsq",
"objectValue": [
11,
1232,
3,
4,
6
],
"type": "array",
"deviceId": "868739057460077",
"formatValue": "[null,\"13.10℃\",\"12.40℃\",\"12.90℃\",\"12.70℃\"]",
"propertyName": "温度",
"createTime": 1636878706315,
"property": "TEMP",
"id": "3cae2cb0be59a5b44af5eb7d5ce945dd",
"value": "[null,13.1,12.4,12.9,12.7]",
"timestamp": 1636878701314
}
},
想要实现的效果:
对objectValue字段指定下标的数据进行聚合操作。
问题:
通过doc['objectValue'][3]获取出来的值,是通过排序了的。不是原始的数据顺序。
查询聚合语句如下:
{
"aggs": {
"avg_grade": {
"avg": {
"script": "doc['objectValue'][3]"
}
}
}
}
期望结果:
"aggregations": {
"avg_grade": {
"value": 4
}
}
返回结果:
"aggregations": {
"avg_grade": {
"value": 33.0
}
}
存储的数据格式如下:
{
"_index": "properties_trsq_rhqsqsq_2021-11",
"_type": "_doc",
"_id": "3cae2cb0be59a5b44af5eb7d5ce945dd",
"_score": 1.0,
"_source": {
"productId": "trsq_rhqsqsq",
"objectValue": [
11,
1232,
3,
4,
6
],
"type": "array",
"deviceId": "868739057460077",
"formatValue": "[null,\"13.10℃\",\"12.40℃\",\"12.90℃\",\"12.70℃\"]",
"propertyName": "温度",
"createTime": 1636878706315,
"property": "TEMP",
"id": "3cae2cb0be59a5b44af5eb7d5ce945dd",
"value": "[null,13.1,12.4,12.9,12.7]",
"timestamp": 1636878701314
}
},
想要实现的效果:
对objectValue字段指定下标的数据进行聚合操作。
问题:
通过doc['objectValue'][3]获取出来的值,是通过排序了的。不是原始的数据顺序。
查询聚合语句如下:
{
"aggs": {
"avg_grade": {
"avg": {
"script": "doc['objectValue'][3]"
}
}
}
}
期望结果:
"aggregations": {
"avg_grade": {
"value": 4
}
}
返回结果:
"aggregations": {
"avg_grade": {
"value": 33.0
}
}
2 个回复
Ombres
赞同来自: kin122
kin122
赞同来自: