【问题标题】:ElasticSearch 6.7 document creation timeElasticSearch 6.7 文档创建时间
【发布时间】:2019-11-30 20:43:51
【问题描述】:

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

【问题讨论】:

    标签: elasticsearch indexing kibana


    【解决方案1】:

    您可以创建ingest pipelinescript processor

    以下示例创建管道set_creation_date,在created_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...
    }
    

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

    【讨论】:

      猜你喜欢
      • 2018-04-30
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 2018-09-23
      • 2019-01-30
      • 1970-01-01
      相关资源
      最近更新 更多