【发布时间】:2015-08-22 18:07:29
【问题描述】:
在指定直方图聚合时,有什么方法可以将字符串转换为浮点数?因为我的文档中的字段是浮点数但没有被 elasticsearch 解析,当我尝试使用字符串字段进行求和时,它会引发下一个错误。
ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData
cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}]"
我知道我可以更改映射,但是对于我的用例,如果我这样做会更方便 在编写 字段的聚合。
这是我的代码:
{
"query" : {
"bool": {"
must": [
{"match": { "sensorId": "D14UD021808ARZC" }},
{"match": { "variableName": "CAUDAL"}}
]
}
},
"aggs" : {
"caudal_per_month" : {
"date_histogram" : {
"field" : "timestamp",
"interval" : "month"
},
"aggs": {
"totalmonth": {
"sum": {
"field": "value",
"script" : "_value*1.0"
}
}
}
}
}
}
【问题讨论】:
标签: string elasticsearch sum aggregation