# Adding dynamic top keys to existing json

**URL:** <https://discuss.elastic.co/t/adding-dynamic-top-keys-to-existing-json/41479>\
**Category:** Logstash\
**Created:** [February 11, 2016, 12:22pm UTC](https://discuss.elastic.co/t/adding-dynamic-top-keys-to-existing-json/41479 "2016-02-11T12:22:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bongo\_zg](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@bongo\_zg](https://discuss.elastic.co/u/bongo_zg)\
**Post date:** [February 11, 2016, 12:22pm UTC](https://discuss.elastic.co/t/adding-dynamic-top-keys-to-existing-json/41479/1 "2016-02-11T12:22:35Z")

</div>

I am manually generating json file that looks typical like

> ```
> { "file1": "value1",
> "file2", "value2" 
> }
> 
> ```

but, I would like to add dynamic top keys like \_id and \_index, but instead of writing them manually, I would like to have them written by logstash, and possibly chosen (values) by me.  
Is it possible?

tnx

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 14, 2016, 4:12pm UTC](https://discuss.elastic.co/t/adding-dynamic-top-keys-to-existing-json/41479/2 "2016-02-14T16:12:22Z")

</div>

I'm assuming what you _actually_ want to do is control the id of the document inserted into Elasticsearch, and the name of the index to which it's inserted. Use the elasticsearch output's `document_id` and `index` options for that. When you extract those documents from ES, the `_id` and `_index` fields will be set to those values.

---

<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 6, 2017, 5:11am UTC](https://discuss.elastic.co/t/adding-dynamic-top-keys-to-existing-json/41479/3 "2017-07-06T05:11:36Z")

</div>


