# How to make dynamic document id from name of the json file

**URL:** <https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577>\
**Category:** Logstash\
**Created:** [March 7, 2020, 7:54pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577 "2020-03-07T19:54:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bahadir\_Eyuboglu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bahadir_eyuboglu/32/64010_2.png) [@Bahadir\_Eyuboglu](https://discuss.elastic.co/u/Bahadir_Eyuboglu)\
**Post date:** [March 7, 2020, 7:54pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577/1 "2020-03-07T19:54:35Z")

</div>

I'm nooby when it's come to elasticsearch what i'm trying to do is, while indexing the large json file want to give it a document id same with file's name  
dummy.json  
document\_id =\> "dummy" kinda

\<  
input {  
file {  
path =\> "/home/abahadir/Desktop/Proje/searchflask/elasticsearch/\*.json"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
codec =\> multiline { pattern =\> "^}" negate =\> true what =\> next auto\_flush\_interval =\> 1 }  
}  
}  
output {  
elasticsearch {  
hosts =\> "[http://localhost:9200](http://localhost:9200)"  
index =\> "restaurants"  
document\_type =\> "docket"  
}  
stdout{ codec =\> rubydebug }  
}  
/\>

if anyone can help i will be greatefull

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 7, 2020, 9:49pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577/2 "2020-03-07T21:49:59Z")

</div>

The file input will add a [path] field to events that contains the filename. You can reference that in the elasticsearch output using

```
document_id => "%{[path]}"
```

---

<div class="post-metadata">

**Author:** ![Bahadir\_Eyuboglu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bahadir_eyuboglu/32/64010_2.png) [@Bahadir\_Eyuboglu](https://discuss.elastic.co/u/Bahadir_Eyuboglu)\
**Post date:** [March 7, 2020, 10:11pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577/3 "2020-03-07T22:11:04Z")

</div>

Is the %{[path]} gives the full path or just the file name ?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 7, 2020, 10:57pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577/4 "2020-03-07T22:57:49Z")

</div>

The full path. If you just want the filename part then you can extract it by copying path to another field and using [mutate+gsub](https://discuss.elastic.co/t/one-or-more-inputs-to-one-or-more-outputs/171906/6) on that.

---

<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 4, 2020, 11:04pm UTC](https://discuss.elastic.co/t/how-to-make-dynamic-document-id-from-name-of-the-json-file/222577/5 "2020-04-04T23:04:12Z")

</div>

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