es7为document自动添加时间戳

需求:为每一条document添加时间戳

解决:es5.0之前是使用 @timestamp 方式解决,es5.0之后该方式废弃,改用 pipeline 方式。

步骤:

1、配置时间戳pipeline:my_timestamp_pipeline

PUT _ingest/pipeline/my_timestamp_pipeline
{
  "description": "Adds a field to a document with the time of ingestion",
  "processors": [
    {
      "set": {
        "field": "timestamp",
        "value": "{{_ingest.timestamp}}"
      }
    }
  ]
}

2、创建索引时使用时间戳pipeline

PUT yzh_index
{
  "settings": {
    "default_pipeline": "my_timestamp_pipeline"
  }
}

3、新增数据

PUT yzh_index/_doc/1
{
  "content": "hello es!"
}

4、验证

GET  yzh_index/_doc/1

 结果:注意时间是国际标准时间,不是东八区的时间!

{
  "_index" : "yzh_index",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "content" : "hello es!",
    "timestamp" : "2022-01-24T09:00:31.571Z"
  }
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值