# Trying to pass mongodb id as elasticsearch id

**URL:** <https://discuss.elastic.co/t/trying-to-pass-mongodb-id-as-elasticsearch-id/262449>\
**Category:** Logstash\
**Created:** [January 28, 2021, 4:31am UTC](https://discuss.elastic.co/t/trying-to-pass-mongodb-id-as-elasticsearch-id/262449 "2021-01-28T04:31:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fidsamurai](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@fidsamurai](https://discuss.elastic.co/u/fidsamurai)\
**Post date:** [January 28, 2021, 4:31am UTC](https://discuss.elastic.co/t/trying-to-pass-mongodb-id-as-elasticsearch-id/262449/1 "2021-01-28T04:31:30Z")

</div>

Logstash 7.8  
We have a case where we collect logs from a mobile app using parse-sdk.  
The data is sent to a MongoDB replicaset.  
Logstash is configured using the mongoschema jdbc driver to pull the data from Mongo and push it to elasticsearch.

Currently however we have the same event being logged twice on occasion even after setting fingerprint with UUID.

In our Mongo document we can see a unique \_id field which becomes document.\_id in elasticsearch.

We tried to set the mongo \_id to the elasticsearch \_id but it all we can see in the \_id field(elasticsearch) is the variable that we set %{[\_id]}

Also tried a mutate filter to first rename from \_id to mongo\_id to no avail.

Code below -

```auto
filter {

mutate {
  rename => ["_id", "mongo_id"] #Also tried to change the _id field to document._id
}

#fingerprint {
# source => "[document._id]"
# target => "[@metadata][fingerprint]"
# method => "MD5"
# key => "1234"
#}

}

output {
elasticsearch {
    hosts => ["http://127.0.0.1:9200"]
  # document_id => "%{[@metadata][uuid]}"
  # document_id => "%{[@metadata][fingerprint]}"
  # doc_as_upsert => true
    document_id => "%{[mongo_id]}"
    codec => json
   }
}

```

Please help

---

<div class="post-metadata">

**Author:** ![bhaskar\_kurzekar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhaskar_kurzekar/32/83032_2.png) [@bhaskar\_kurzekar](https://discuss.elastic.co/u/bhaskar_kurzekar)\
**Post date:** [January 28, 2021, 6:40am UTC](https://discuss.elastic.co/t/trying-to-pass-mongodb-id-as-elasticsearch-id/262449/2 "2021-01-28T06:40:37Z")

</div>

no need to rename just simple add array as document [document][\_id]

output {  
elasticsearch {  
hosts =\> ["[http://127.0.0.1:9200](http://127.0.0.1:9200)"]  
doc\_as\_upsert =\> true  
document\_id =\> "%{[document][\_id]}"  
codec =\> json  
}  
}

---

<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:** [February 25, 2021, 6:40am UTC](https://discuss.elastic.co/t/trying-to-pass-mongodb-id-as-elasticsearch-id/262449/3 "2021-02-25T06:40:52Z")

</div>

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