# Insert ingest pipeline if id is new

**URL:** <https://discuss.elastic.co/t/insert-ingest-pipeline-if-id-is-new/172945>\
**Category:** Elasticsearch\
**Created:** [March 19, 2019, 10:32am UTC](https://discuss.elastic.co/t/insert-ingest-pipeline-if-id-is-new/172945 "2019-03-19T10:32:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Constantin\_Manea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constantin_manea/32/42319_2.png) [@Constantin\_Manea](https://discuss.elastic.co/u/Constantin_Manea)\
**Post date:** [March 19, 2019, 10:32am UTC](https://discuss.elastic.co/t/insert-ingest-pipeline-if-id-is-new/172945/1 "2019-03-19T10:32:51Z")

</div>

Hello all,

I'm kinda new at elasticsearch and i have a bit of a situation:

Every 3-4 days i receive a big file (around 30 mil. documents) to insert into elasticsearch. I process the file line by line and insert into elasticsearch. The thing is, each new file is exactly like the last one but with a few changes (i don't know where the changes are). I receive the full files and i rely on elasticsearch to insert only the diffs. I do this by computing a hash based on a few fields and if there are some changes, the hash will be different. Then i use the hash as the id of the document. If a new file contains the same document as an older file, i insert it again and elasticsearch just increments the \_version field and that's all.

The problem:  
I need two fields in each document:

- first\_seen: When the index was first created
- last\_seen: Updated everytime this id(hash) is inserted again

How can i do this in elasticsearch?

I've created a ingest pipeline:

```
PUT _ingest/pipeline/createddate
{
  "description": "add timestamp field to the document, requires a datetime field date mapping",
  "processors": [
    {
      "date" : {
        "field" : "last_seen",
        "formats" : ["yyyy-MM-dd"],
        "target_field": "first_seen"
      }
    }
  ]
}

```

that gets the "first\_seen" value from the insert and sets it to "last\_seen" BUT i want this to happen only for new IDs (new hashes).  
This one applyes everytime so when i insert again this id, both dates (last\_seen and first\_seen) gets updated.

Hope i made myself clear and that someone can help me

---

<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:** [April 16, 2019, 10:32am UTC](https://discuss.elastic.co/t/insert-ingest-pipeline-if-id-is-new/172945/2 "2019-04-16T10:32:52Z")

</div>

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