# Only Process Newly indexed documents

**URL:** <https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785>\
**Category:** Elasticsearch\
**Created:** [December 14, 2017, 2:03pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785 "2017-12-14T14:03:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparklegoat](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sparklegoat](https://discuss.elastic.co/u/sparklegoat)\
**Post date:** [December 14, 2017, 2:03pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/1 "2017-12-14T14:03:27Z")

</div>

Is there a way to get the date and time that an elastic search document was written? Looking to run over data hourly and not have to consume data I have already processed in prior runs. The negatives to the options I have are listed in the below but I am trying to exhaust all the possibilities before making an implementation.

I am running es queries via spark and would prefer NOT to look through all documents that I have already processed. Instead I would like read the only documents that were ingested between the last time the program ran and now.

What is the best most efficient way to do this?

I have looked at;

- updating to add a field with an array with booleans for if its been looked at by which analytic. The negative is waiting for the update to occur.
- index per time frame method, which would be to break down the current indexes into smaller ones so by hour.The negative I see is the number of open file descriptors.
- ??  
Elasticsearch version 5.6

---

<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:** [December 14, 2017, 2:14pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/2 "2017-12-14T14:14:52Z")

</div>

You could set a timestamp when the document reaches Elasticsearch using [an index pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/accessing-data-in-pipelines.html#accessing-ingest-metadata).

---

<div class="post-metadata">

**Author:** ![sparklegoat](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sparklegoat](https://discuss.elastic.co/u/sparklegoat)\
**Post date:** [December 14, 2017, 2:41pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/3 "2017-12-14T14:41:02Z")

</div>

Thank you. I am looking into this. Is there a delay from the pipeline util when I can read the document? Also for this to work I would need to walk through a time range right? Last run - now() type of logic.

---

<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:** [December 14, 2017, 2:44pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/4 "2017-12-14T14:44:33Z")

</div>

You can read the document directly by ID, but will have to wait until a refresh takes place before it can be searched. This would require time range logic adjusted based on your refresh interval and how long a refresh usually takes.

---

<div class="post-metadata">

**Author:** ![sparklegoat](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sparklegoat](https://discuss.elastic.co/u/sparklegoat)\
**Post date:** [December 14, 2017, 3:11pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/5 "2017-12-14T15:11:20Z")

</div>

"Ingest metadata is transient and is lost after a document has been processed by the pipeline", so would I even be able to see this field? How would I know which document IDs to process with the field gone?

---

<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:** [December 14, 2017, 3:26pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/6 "2017-12-14T15:26:39Z")

</div>

The example I linked to shows how to copy this timestamp into the document on indexing. You then have it on the document and can retrieve data based on it.

---

<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:** [January 11, 2018, 3:26pm UTC](https://discuss.elastic.co/t/only-process-newly-indexed-documents/111785/7 "2018-01-11T15:26:40Z")

</div>

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