How to automatically set the server date/time when adding data?

Bonjour Vincent! :wink:

I believe you can do something like this using an ingest pipeline with a Set processor.

And you can make the pipeline a default pipeline for your index. (See Ingest pipelines | Elasticsearch Guide [7.17] | Elastic)

Full example (from this example Ingest pipelines | Elasticsearch Guide [7.17] | Elastic):

PUT _ingest/pipeline/set-timestamp
{
  "description": "sets the timestamp",
  "processors": [
    {
      "set": {
        "field": "timestamp",
        "value": "{{{_ingest.timestamp}}}"
      }
    }
  ]
}
DELETE test
PUT test
{
  "settings": {
    "index.default_pipeline": "set-timestamp"
  },
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date"
      }
    }
  }
}
PUT test/_doc/1
{
  "foo": "bar"
}
GET test/_doc/1

Gives:

{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "foo" : "bar",
    "timestamp" : "2022-02-09T10:47:34.880561Z"
  }
}