识别Kibana和ElasticSearch中的时间戳

use*_*249 5 mapping json curl elasticsearch kibana

我是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"}
Run Code Online (Sandbox Code Playgroud)

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

curl -XPUT 'http://localhost:9200/test/'
Run Code Online (Sandbox Code Playgroud)

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

curl -XPUT 'http://localhost:9200/test/container/_mapping' -d'
{
"container" : {
"_timestamp" : {
"_timestamp" : {"enabled: true, "type":"date", "format": "date_hour_minute_second_fraction", "store":true}
}
}
}'
Run Code Online (Sandbox Code Playgroud)

//来自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
Run Code Online (Sandbox Code Playgroud)

所有这些命令都运行无故障,但是当在Kibana中查看数据时,_timestamp字段无法被识别.通过时间戳排序不起作用,尝试使用不同的句点过滤数据不起作用.关于为什么会出现这个问题的任何想法都是昂贵的.

use*_*249 7

管理解决问题.所以对于有这个问题的其他人:

我们保存日期的格式不正确,需要:

"_timestamp":"2013-07-05 08:49:30.123"
Run Code Online (Sandbox Code Playgroud)

那么我们的映射需要是:

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"}
}
}'
Run Code Online (Sandbox Code Playgroud)

希望这有助于某人.


jav*_*der 6

如果您有纪元时间戳,则无需制作和ISO8601日期.为了使Kibana识别该字段,因为日期必须是日期字段.

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

可以粘贴到奇迹/感知插件的简单示例:

# 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
Run Code Online (Sandbox Code Playgroud)

在serie中运行这些命令.

生成免费的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
Run Code Online (Sandbox Code Playgroud)

在弹性搜索中检查数据

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

GET /logger/mem/_search
Run Code Online (Sandbox Code Playgroud)

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