需求:根据时间提取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索引中插入数据验证

新增和更新时都会刷新此字段的值
配置Elasticsearch的ingestpipeline,通过设置default_pipeline在索引创建时自动添加时间戳字段ingest_timestamp,并更新索引映射以定义该字段为日期类型。此过程确保每次数据插入或更新时,时间戳字段都会得到刷新。
679

被折叠的 条评论
为什么被折叠?



