elasticsearch - ElasticSearch 6.7 document creation time
问题描述
I want each document that I store into my ES index to have a creation time by default like datetime.now (NOT set by the client who sends the PUT request but set by the ES itself). Is there a way to do that? Or do I have to pass the value during indexing my document in PUT request?
解决方案
You can create an ingest pipeline and script processor.
The following example create a pipeline set_creation_date
adding the document date of creation in the created_at
field.
PUT _ingest/pipeline/set_creation_date
{
"description": "Set creation date",
"processors": [
{
"script": {
"source": "ctx.created_at = new Date();"
}
}
]
}
When you index a document add the name of the pipeline in the pipeline
query param.
POST /my_index/_doc?pipeline=set_creation_date
{
// Your doc...
}
For this to work, you must have at least one ingest node.
推荐阅读
- python - 使用请求python模块发送删除请求但正文只是字符串而不是json?
- javascript - Datatables jQuery 获取行数据移动/PC 视图
- javascript - Array.length 说它是 0,即使它不是 React/Javascript/Typescript
- python - 在python中将复杂字符串转换为json
- laravel - 如何在 Laravel 中查找、更新和取回对象集合?
- maven - 由于 relativePath,在镶木地板工具上构建失败
- python - EKG 传感器数据的实时绘图在小于 600 毫秒的小间隔内不工作
- python - 提取 zip 文件并将其存储到图像或文件字段
- javascript - 当用户单击刷新或仅使用纯 Javascript 按下 F5 按钮时,如何调用/执行函数?
- android - NavDeepLinkBuilder 未重定向到目标片段