Search code examples
elasticsearchbulkinsertbulkupdate

Elasticsearch: How to add "created_at" and "updated_at" timestamps?


I have a database where I should store created_at and updated_at fields for each document.

The created_at field should be created once on first document insert.

The updated_at field should be created on first document insert and should be updated via Bulk API on each update, even if none of the document fields are changed.

The question is: how to add those timestamps?


Solution

  • I believe that Elasticsearch used to have a feature to add these automatically, but it was removed in later versions to improve performance. You would have to add these fields to your mapping and then implement a process to set those fields. One way to do this is with an ingest pipeline, which someone explains in the ES forum. You will want to check the docs for how to implement pipelines with your particular version of Elasticsearch.

    Suggestion: You should always check the forums for Elasticsearch questions. The community seems to be more active on there, and devs will also often respond to questions.