我必须索引包含'time'字段的文档,该字段的值是一个整数,表示自纪元以来的秒数(也称为unix时间戳).
我一直在阅读ES文档并发现了这个:
http://www.elasticsearch.org/guide/reference/mapping/date-format.html
但似乎如果我想提交unix时间戳并希望它们存储在'date'字段中(整数字段对我没用)我只有两个选项:
我错过了还有其他选择吗?
谢谢!
dre*_*ewr 18
如果您提供告诉ES该字段是日期的映射,则可以使用epoch millis作为输入.如果您希望ES自动检测,您必须提供ISO8601或其他可发现的格式.
更新:我还应该注意,您可以影响ES将在映射中识别为日期的字符串.http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html
如果您想使用我期望的 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
Run Code Online (Sandbox Code Playgroud)
依次运行这些命令中的每一个。
这是一个简单的脚本,它会回显到您的终端并记录到您的本地 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 将自动检测您的日期字段。
| 归档时间: |
|
| 查看次数: |
28674 次 |
| 最近记录: |