ElasticSearch系列---【在已有索引中添加新的字段】

1.问题描述

消费kafka的数据,写入es,为了查看推送时间和消费时间的时间差值,我们需要在原有的es索引core_pri_flow_202405中添加新字段produce_time和create_time。

2.直接使用devtools添加新字段

#使用Easy-Es框架,实体类中添加字段
@IndexField(value="produce_time",fieldType=FieldType.DATE,dateFormat="yyyy-MM-dd HH:mm:ss.SSS||epoch_millis")
private String produceTime;

#查看现有mapping结构
GET /core_pri_flow_202405/_mapping

#在已有的索引上新增新字段,epoch_millis:表示自1970年1月1日00:00:00 UTC以来的毫秒数
PUT /core_pri_flow_202405/_mapping
{
  "properties": {
    "produce_time": {
      "type": "date",
      "format": "yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
    },
    "create_time": {
      "type": "date",
      "format": "yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
    }
  }
}

posted on 2024-07-08 22:37  少年攻城狮  阅读(8)  评论(0编辑  收藏  举报

导航