需求:根据时间提取es数据
解决:为es的记录添加时间戳
1、配置时间戳pipeline
http://192.168.0.213:9200/_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}}"
}
}
]
}
2、配置setting
如果已经创建了索引,则更新setting配置;
没有创建索引,则在创建索引语句中添加配置 default_pipeline
http://192.168.0.213:9200/linkmecha-flow-log/_settings
{
"default_pipeline": "my_timestamp_pipeline"
}
3、es索引中添加字段
http://192.168.0.213:9200/flow-log/_mapping/_doc?include_type_name=true
{
"properties": {
"ingest_timestamp": {
"type": "date"
}
}
}
4、最后向es索引中插入数据验证
新增和更新时都会刷新此字段的值