我有一组要对其执行聚合的文档: sum the values of 'sessions' field 。“会话”的字段类型是字符串,在执行聚合时必须将其转换为整数字段。
防爆文件:
{
"bounceRate": "100.0",
"avgSessionDuration": "0.0",
"sessions": "1",
}
我的查询:
{
"query": {
"match_all": {}
},
"aggs": {
"total_sessions": {
"sum": {
"script": {
"inline": "Float.parseFloat(doc['ga:sessions'].value)"
}
}
}
}
}
错误:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "failed to run inline script [Float.parseFloat(doc[sessions'].value)] using lang [groovy]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "testindex",
"node": "0Kgq1cQKT2OvFSGu5E6ptw",
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [Float.parseFloat(doc['sessions'].value)] using lang [groovy]",
"caused_by": {
"type": "missing_property_exception",
"reason": "No such property: Float for class: 02f31d7c14f9b59a358a82c6bbf3853fa90738ec"
}
}
}
]
},
"status": 500
}
为什么显示缺少属性异常?如何引用脚本中的“会话”字段?
更新:解决方案是在索引之前执行正确的映射,这要归功于Val
快速响应。