【问题标题】:Recognising timestamps in Kibana and ElasticSearch在 Kibana 和 ElasticSearch 中识别时间戳
【发布时间】:2014-11-27 07:06:38
【问题描述】:

我是 ElasticSearch 和 Kibana 的新手,无法让 Kibana 识别我的时间戳。

我有一个 JSON 文件,其中包含我希望使用 Curl 插入到 Elasticsearch 中的大量数据。这是其中一个 JSON 条目的示例。

{"index":{"_id":"63"}}
{"account_number":63,"firstname":"Hughes","lastname":"Owens", "email":"hughesowens@valpreal.com", "_timestamp":"2013-07-05T08:49:30.123"}

我尝试使用以下命令在 Elasticsearch 中创建索引:

curl -XPUT 'http://localhost:9200/test/'

然后我尝试为时间戳设置适当的映射:

curl -XPUT 'http://localhost:9200/test/container/_mapping' -d'
{
"container" : {
"_timestamp" : {
"_timestamp" : {"enabled: true, "type":"date", "format": "date_hour_minute_second_fraction", "store":true}
}
}
}'

//http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html的时间戳格式

然后我尝试批量插入我的数据:

curl -XPOST 'localhost:9200/test/container/_bulk?pretty' --data-binary @myfile.json

所有这些命令都可以正常运行,但是在 Kibana 中查看数据时,_timestamp 字段无法识别。通过时间戳排序不起作用,尝试使用不同时期过滤数据也不起作用。任何关于为什么会发生此问题的想法都已得到应用。

【问题讨论】:

    标签: json curl elasticsearch mapping kibana


    【解决方案1】:

    设法解决了问题。所以对于其他有这个问题的人:

    我们保存日期的格式不正确,应该是:

    "_timestamp":"2013-07-05 08:49:30.123"
    

    那么我们的映射需要是:

    curl -XPUT 'http://localhost:9200/test/container/_mapping' -d'
    {
    "container" : {
    "_timestamp" : {"enabled": true, "type":"date", "format": "yyyy-MM-dd HH:mm:ss.SSS", "store":true, "path" : "_timestamp"}
    }
    }'
    

    希望这对某人有所帮助。

    【讨论】:

    • 您的数据天生就有 _timestamp 字段作为 JSON 键值对?映射不会使elasticsearch插入时间戳吗?
    • 使用最新版本的 Elastic Search (5.1.1) 我必须使用以下格式:"timestamp": "2016-12-15T11:34:10.000"。请注意 T 和字段名称 _timestamp 不被接受。
    • @Marc 非常感谢您!在日期和时间之间使用 T 甚至在 5.3 上仍然可以正常工作
    【解决方案2】:

    如果您有纪元时间戳,则无需制作 ISO8601 日期。不过,要让 Kibana 将该字段识别为日期,它必须是一个日期字段。

    请注意,您必须将字段设置为日期类型您将任何数据输入/index/type。否则它将被长期存储且不可更改。

    可以粘贴到marvel/sense插件中的简单示例:

    # Make sure the index isn't there
    DELETE /logger
    
    # Create the index
    PUT /logger
    
    # Add the mapping of properties to the document type `mem`
    PUT /logger/_mapping/mem
    {
      "mem": {
        "properties": {
          "timestamp": {
            "type": "date"
          },
          "free": {
             "type": "long"
          }
        }
      }
    }
    
    # Inspect the newly created mapping
    GET /logger/_mapping/mem
    

    依次运行这些命令。

    生成免费的内存日志

    这是一个简单的脚本,它会回显到您的终端并记录到您的本地 elasticsearch:

    while (( 1==1 )); do memfree=`free -b|tail -n 1|tr -s ' ' ' '|cut -d ' ' -f4`; echo $load; curl -XPOST "localhost:9200/logger/mem" -d "{ \"timestamp\": `date +%s%3N`, \"free\": $memfree }"; sleep 1; done
    

    在弹性搜索中检查数据

    将此粘贴​​到您的奇迹/感觉中

    GET /logger/mem/_search
    

    现在您可以转移到 Kibana 并制作一些图表。 Kibana 将自动检测您的日期字段。

    【讨论】:

      【解决方案3】:

      此解决方案适用于旧版 ES https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-08
        • 2019-12-10
        相关资源
        最近更新 更多