# Best practice for integrating automated created\_at & updated\_at fields in Elasticsearch 8.4

**URL:** https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634
**Category:** Elasticsearch
**Tags:** ingest-pipeline
**Created:** [September 18, 2022, 5:34am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634 "2022-09-18T05:34:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sabbir\_Talukdar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sabbir_talukdar/32/99497_2.png) [@Sabbir\_Talukdar](https://discuss.elastic.co/u/Sabbir_Talukdar)
#### Post date: [September 18, 2022, 5:34am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/1 "2022-09-18T05:34:33Z")

</div>

Hello, this is my first transition from other DB (SQL / NOSQL based) to Elasticsearch.  
I am having troubles choosing the best practiced methods of integrating `created_at` & `updated_at` fields.  
I am familiar with `ingest_pipelines` for adding created\_at fields while indexing a document, however I am aware that `Update API` do not support ingest\_pipelines yet. So in order to circumvent this problem, we can use `scripted_upsert` to modify updated\_at field. But I am not sure if this is the most recommended way to integrate `created_at` & `updated_at` in the DB. Could you share some ideas on how to store and modify `updated_at` & `created_at` ? TIA.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2022, 5:51am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/3 "2022-09-18T05:51:10Z")

</div>

Welcome!

The best practice is to control that from the source application which actually creates the document.

What is the source application? Could you tell more about your use case?

In general, I never use the update API but only the Index API. Why do you need the update API here?

---

<div class="post-metadata">

### Author: ![Sabbir\_Talukdar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sabbir_talukdar/32/99497_2.png) [@Sabbir\_Talukdar](https://discuss.elastic.co/u/Sabbir_Talukdar)
#### Post date: [September 18, 2022, 5:58am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/4 "2022-09-18T05:58:31Z")

</div>

@dadoonet

1. i use Index API to index a new document, and Update API to modify an existing document.
2. My source application is just a group of REST API who is in charge of performing normal CRUD operations.

> The best practice is to control that from the source application which actually creates the document.

by this, do you mean I just append a created\_at / updated\_at field to the JSON before indexing a new document or updating an existing one?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2022, 6:30am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/5 "2022-09-18T06:30:19Z")

</div>

Why not using the index API when you want to modify the document?

I mean that behind the scene, the Update API is just:

- GET the old document
- Merge it with the new one
- Index this full document

> [@Sabbir\_Talukdar](#):
>
> by this, do you mean I just append a created\_at / updated\_at field to the JSON before indexing a new document or updating an existing one?

Yes.

---

<div class="post-metadata">

### Author: ![Sabbir\_Talukdar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sabbir_talukdar/32/99497_2.png) [@Sabbir\_Talukdar](https://discuss.elastic.co/u/Sabbir_Talukdar)
#### Post date: [September 18, 2022, 6:59am UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/6 "2022-09-18T06:59:03Z")

</div>

@dadoonet  
Thank you for your reply.  
I think I am going to use Index API instead of Update API.  
So now, do you think I should control created\_at updated\_at from source application or just write an ingest\_pipeline for that, as I dont have any dependency on Update API?

Sorry to make this post long, will be closing this after this reply. Thank you for helping me out!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2022, 4:47pm UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/7 "2022-09-18T16:47:39Z")

</div>

IMHO it's always better to do most of the things on the app side. So elasticsearch has less to do and it's easier for you to maintain.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 16, 2022, 4:48pm UTC](https://discuss.elastic.co/t/best-practice-for-integrating-automated-created-at-updated-at-fields-in-elasticsearch-8-4/314634/8 "2022-10-16T16:48:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
