【问题标题】:changing the timestamp format of elasticsearch index更改elasticsearch索引的时间戳格式
【发布时间】:2019-09-19 18:32:22
【问题描述】:

我正在尝试将日志记录加载到 elasticsearch (7.3.1) 并在 kibana 中显示结果。我面临的事实是,虽然记录被加载到 elasticearch 并且 curl GET 显示它们,但它们在 kibana 中不可见。

大多数时候,这是因为时间戳格式。就我而言,正确的时间戳格式应该是 basic_date_time,但索引只有:

# curl -XGET 'localhost:9200/og/_mapping'
{"og":{"mappings":{"properties":{"@timestamp":{"type":"date"},"componentName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}% 

我想将格式“basic_date_time”添加到@timestamp 属性,但我所做的每次尝试要么不被elasticsearch 接受,要么不更改索引字段。 我只是没有得到正确的命令来完成这项工作。

例如,我能想到的最简单的,

Z cr 23;curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/og/_mapping' -d'
{"mappings":{"properties":{"@timestamp":{"type":"date","format":"basic_date_time"}}}}
'

报错

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [mappings : {properties={@timestamp={format=basic_date_time, type=date}}}]"}],"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [mappings : {properties={@timestamp={format=basic_date_time, type=date}}}]"},"status":400}% 

并尝试通过 kibana 使用

PUT /og
{
  "mappings": {
    "properties": {
      "@timestamp":    { "type": "date", "format": "basic_date_time" } 
    }
  }
}

给予

{
  "error": {
    "root_cause": [
      {
        "type": "resource_already_exists_exception",
        "reason": "index [og/NIT2FoNfQpuPT3Povp97bg] already exists",
        "index_uuid": "NIT2FoNfQpuPT3Povp97bg",
        "index": "og"
      }
    ],
    "type": "resource_already_exists_exception",
    "reason": "index [og/NIT2FoNfQpuPT3Povp97bg] already exists",
    "index_uuid": "NIT2FoNfQpuPT3Povp97bg",
    "index": "og"
  },
  "status": 400
}

我不确定我是否应该在 kibana 中尝试这个。但如果我能找到正确的 curl 命令来更改索引,我会非常高兴。

感谢您的帮助,路德

【问题讨论】:

  • 我必须承认我可能误解了这个问题。症状是最近的日志记录没有出现在 kibana 中。我认为它必须对日期格式做一些事情,但经过一些测试,我怀疑时区是原因。也许 kibana 认为这些记录是未来的,并没有显示出来。时间戳看起来像“@timestamp”:“2019-09-12T00:47:12.165+00:00”。当我创建 12 小时前的记录时,它们会显示出来。所以这不是日期问题,而是时间问题。
  • 在 Kibana 的时间选择器中尝试将显示的时间间隔延长到更远的过去和更远的未来。这样您就可以查看是否是时间问题。
  • 我什至没有意识到这是可能的。我将时间规范更改为“下一个 5 小时”,确实:它向我显示了丢失的 4 条记录。但是现在:我该怎么做才能让 kibana 对“现在”的含义与生成日志记录的软件有相同的想法?
  • 您可以通过转到管理 > 高级设置来配置 Kibana 应该工作的时区。
  • 我意识到日志记录指定了错误的时区。由于时区是 CEST,因此日志记录应指定 +02:00。通过该更正,kibana 可以正确显示它们。

标签: elasticsearch kibana


【解决方案1】:

你可以像这样通过 curl 做到这一点:

curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/og/_mapping' -d '{
  "properties": {
    "@timestamp": {
      "type": "date",
      "format": "basic_date_time"
    }
  }
}

'

或者像这样在 Kibana 中:

PUT /og/_mapping
{
  "properties": {
    "@timestamp": { 
        "type": "date", 
        "format": "basic_date_time" 
    } 
  }
}

另外值得注意的是,一旦创建了索引/映射,您通常不能对其进行修改 (very few exceptions)。您可以使用正确的映射创建一个新索引并将您的数据重新索引到其中。

【讨论】:

  • 给出错误信息{"type":"illegal_argument_exception","re​​ason":"Mapper for [@timestamp] 与现有映射冲突:\n[mapper [@timestamp] 具有不同的 [格式] 值]"}]
  • 是的,一旦创建,您通常不能修改映射(极少数例外)。您可以使用正确的映射创建一个新索引,并将您的数据重新索引到其中。
  • 我删除了索引和索引模式。但是上面的错误信息不断出现。鉴于我的真正问题已解决,我应该停止尝试更改格式。感谢 Val 的帮助。
  • 我会接受 Val;我还没有这样做,因为真正帮助我的是你对我的问题的评论。我应该能够接受,而不是这个答案....
  • 酷,我也在我的答案中添加了该评论!
猜你喜欢
  • 1970-01-01
  • 2018-11-27
  • 1970-01-01
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-26
相关资源
最近更新 更多