Adding dynamic top keys to existing json

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

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.