es7自动添加时间戳

需求:根据时间提取es数据
解决:为es的记录添加时间戳
方法:
es5.0以前的版本使用的是@time_stamp方式来给document的每一条记录添加时间戳,

"properties": {
         "@timestamp":{
                   "format":"strict_date_optional_time||epoch_millis",
                   "type":"date",
                   "enabled":true
         }
}

es5.0以后,这种方式就被放弃了,到目前为止(最新7.12),es采用的是pipeline的方式来自动添加时间戳:

  1. 配置时间戳pipeline
PUT _ingest/pipeline/my_timestamp_pipeline
{
  "description": "Adds a field to a document with the time of ingestion",
  "processors": [
    {
      "set": {
        "field": "ingest_timestamp",
        "value": "{{_ingest.timestamp}}"
      }
    }
  ]
}
  1. 创建索引时使用时间戳pipeline
PUT my_index
{
  "settings": {
    "default_pipeline": "my_timestamp_pipeline"
  }
}
  1. 创建数据验证:

PUT my_index/_doc/1
{
  "content": "it is cool!"
}

结果:注意这里的时间时标准时间,不是东八区的时间。


{
  "_index" : "my_index",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "content" : "it is cool!",
    "ingest_timestamp" : "2021-03-11T12:39:09.921Z"
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值