首页 > 解决方案 > 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?

标签: elasticsearchindexingkibana

解决方案


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.


推荐阅读