2

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?

Prisacari Dmitrii
  • 1,985
  • 1
  • 23
  • 33
  • Does this answer your question? [How to make elasticsearch add the timestamp field to every document in all indices?](https://stackoverflow.com/questions/17136138/how-to-make-elasticsearch-add-the-timestamp-field-to-every-document-in-all-indic) – Aleksi Nov 13 '20 at 05:12

1 Answers1

2

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.

  • 1
    Unfortunately as for elasticsearch v7.2 I've not found any other way to add those timestamps but ingest pipelines and update/upsert scripts. Accepting this answer. – Prisacari Dmitrii Aug 23 '19 at 07:54