ElasticSearch 6.7 文档创建时间

ElasticSearch 6.7 document creation time

我希望存储到我的 ES 索引中的每个文档在默认情况下都有一个创建时间,如 datetime.now(不是由发送 PUT 请求的客户端设置,而是由 ES 本身设置)。有没有办法做到这一点?或者我是否必须在 PUT 请求中为我的文档编制索引时传递该值?

您可以创建 ingest pipeline and script processor

以下示例创建管道 set_creation_datecreated_at 字段中添加文档创建日期。

PUT _ingest/pipeline/set_creation_date
{
    "description": "Set creation date",
    "processors": [
      {
        "script": {
          "source": "ctx.created_at = new Date();"
        }
      }
    ]
}

索引文档时pipeline查询参数中添加管道名称

POST /my_index/_doc?pipeline=set_creation_date
{
   // Your doc...
}

为此,您必须至少有一个摄取节点。