ES update_time 字段 更新时间

search_key_word :

time 写入精度 update_time 字段 更新时间

说明:

  1. 在 5.0 版本之前可以开启 _timestamp 元数据字段,会自动为文档添加一个时间戳,但此元数据字段已在 2.x 版本过时,5.x 版本移除 (release nodes)

  2. 在 5.x 及之后的版本中可以利用 pipeline 为文档写入 es 时添加一个时间戳字段来达到同样的效果

  3. 索引里默认没有update_time 字段,如需要此字段则需要参考后文手动添加。

创建 pipeline

创建 pipeline 名称可任意定义,添加的时间戳字段名不要和业务数据中的字段名相同,相同则会覆盖了业务字段的值。这里没有直接使用 set processor { {_ingest.timestamp}} 设置为更新时间,是因为 { {_ingest.timestamp}} 会使用 UTC 时间,且在 set processor 里无法转换时区

 
 

PUT _ingest/pipeline/add_update_time

{
    "description": "add update_time field",
    "processors": [{
        "script": {
            "lang": "painless",
            "source": "ctx.update_time = System.currentTimeMillis()"
        }
    }]
}

为 index 设置 pipeline

为新建索引设置

 
 

PUT set_pipeline_for_new_index 

{
    "settings": {
        "index.default_pipeline": "add_update_time"
    },
    "mappings": {
        "properties": {
            "name": {
                "type": "keyword"
            },
            "age": {
                "type": "integer"
            }
        }
    }
}

为已有索引设置

 
 

PUT set_pipeline_for_exists_index/_settings { "settings": { "index.default_pipeline": "add_update_time" } }

猜你喜欢

转载自blog.csdn.net/qq_32907195/article/details/131063198