Elasticsearch

时间:2016-08-12 06:40:31

标签: elasticsearch elasticsearch-aggregation

我有一组文档,我想在其中执行聚合:总结'sessions'字段的值。 'sessions'的字段类型是字符串,在执行聚合时,它必须转换为整数字段。

前文件:

{

"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
}

为什么显示缺少属性异常?如何引用脚本中的'session'字段?

更新:解决方案是在编制索引之前执行正确的映射,感谢 Val 以获得快速响应。

0 个答案:

没有答案