Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save renshuki/34b732411d4bbfc9bf1a9ca75c569f79 to your computer and use it in GitHub Desktop.
Save renshuki/34b732411d4bbfc9bf1a9ca75c569f79 to your computer and use it in GitHub Desktop.
Elasticsearch - Ingest pipeline to add a timestamp field to a document at the time of the ingestion

Create the ingest pipeline

PUT _ingest/pipeline/timestamp
{
  "description": "Add a timestamp field to a document at the time of the ingestion",
  "processors": [
    {
      "set": {
        "field": "@timestamp",
        "value": "{{_ingest.timestamp}}"
      }
    }
  ]
}

Create a index / document using the pipeline

POST auto_timestamp/_doc?pipeline=timestamp
{
  "msg": "Timestamp auto-generation"
}

Search the created document

GET auto_timestamp/_search

Result

"hits" : [
  {
    "_index" : "auto_timestamp",
    "_type" : "_doc",
    "_id" : "uqNXJGoBvxBjcKDft4xM",
    "_score" : 1.0,
    "_source" : {
      "msg" : "Check out the automated Timestamp generation!",
      "@timestamp" : "2019-04-16T04:11:29.484Z"
    }
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment