# How to add a Runtime Field for doc ingest time?

**URL:** <https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [May 27, 2022, 11:18am UTC](https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793 "2022-05-27T11:18:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ykara84](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ykara84/32/106391_2.png) [@ykara84](https://discuss.elastic.co/u/ykara84)\
**Post date:** [May 27, 2022, 11:18am UTC](https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793/1 "2022-05-27T11:18:05Z")

</div>

Hi, i'm trying to add a **Runtime Field** to an index-pattern which will add a new field to each doc as it arrives into the index, the new field is to contain the date/time the doc was added to the index, a field called something like _ingested\_on_.

How do I do this? I understand I need to use a Painless script?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 30, 2022, 7:46pm UTC](https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793/2 "2022-05-30T19:46:48Z")

</div>

Runtime fields are evaluated at query time and do not add data at index time. It sounds like you instead want to use an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/ingest.html) with a [set processor](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/set-processor.html) that sets the `ingested_on` field to the current timestamp based on the `_ingest.timestamp` metadata field. See [this example](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/ingest.html#access-ingest-metadata) for further details.

---

<div class="post-metadata">

**Author:** ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)\
**Post date:** [June 24, 2022, 11:15am UTC](https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793/3 "2022-06-24T11:15:08Z")

</div>

If you need more examples and guidance you can also check this [Elastic Runtime Field examples](https://elastic-content-share.eu/elastic-runtime-field-example-repository/) repository

---

<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:** [July 22, 2022, 11:15am UTC](https://discuss.elastic.co/t/how-to-add-a-runtime-field-for-doc-ingest-time/305793/4 "2022-07-22T11:15:41Z")

</div>

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