Field [@timestamp] of type [keyword] does not support custom formats

拼搏现实的明天。 2024-04-18 11:44 188阅读 0赞

问题描述

执行es的聚合histogram 或者date_histogram 返回错误。

传入报文:

  1. {
  2. "size":0,
  3. "aggs":{
  4. "calltime":{
  5. "date_histogram":{
  6. "field":"@timestamp",
  7. "interval":"minute",
  8. "format" : "yyyy-MM-dd'T'HH:mm:ss"
  9. }
  10. }
  11. }
  12. }

返回报错:

  1. {
  2. "error": {
  3. "root_cause": [ {
  4. "type": "illegal_argument_exception",
  5. "reason": "Field [@timestamp] of type [keyword] does not support custom formats"
  6. }],
  7. "type": "search_phase_execution_exception",
  8. "reason": "all shards failed",
  9. "phase": "query",
  10. "grouped": true,
  11. "failed_shards": [ {
  12. "shard": 0,
  13. "index": "esb-srvlog-2019-07-21",
  14. "node": "nruodlnbT8u0tJKTzRs9Eg",
  15. "reason": {
  16. "type": "illegal_argument_exception",
  17. "reason": "Field [@timestamp] of type [keyword] does not support custom formats"
  18. }
  19. }]
  20. },
  21. "status": 400
  22. }

原因分析

先通过mapping看看索引的mapping:
在这里插入图片描述
发现@timestamp这个字段是被设置成了 keyword类型。所以es将该字段只是视为关键字的字符串,而不是日期的类型。故也就无法对该字段进行日期的统计。

解决方法

出现类似上面的这种问题,只有重新设置索引类型,将该字段改成所期望的类型,这里应该是。通过PUT方法。如:
在这里插入图片描述

需要注意的是,重新设置索引后只能对后面插入的文档有效,之前的文档类型不会被改变。

发表评论

表情:
评论列表 (有 0 条评论,188人围观)

还没有评论,来说两句吧...

相关阅读