# Get \_id document on query

**URL:** <https://discuss.elastic.co/t/get-id-document-on-query/183732>\
**Category:** Logstash\
**Created:** [May 31, 2019, 1:32pm UTC](https://discuss.elastic.co/t/get-id-document-on-query/183732 "2019-05-31T13:32:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pr0b3l](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pr0b3l](https://discuss.elastic.co/u/pr0b3l)\
**Post date:** [May 31, 2019, 1:32pm UTC](https://discuss.elastic.co/t/get-id-document-on-query/183732/1 "2019-05-31T13:32:22Z")

</div>

Hello!  
I need to get id in previous document.

My query:  
query.json

> {  
> "size" : 1,  
> "sort" : [{"timestamp": "desc"}],  
> "query": {  
> "query\_string": {  
> "query": "AS:%{[name]}"  
> }  
> },  
> "\_id": "%{[@metadata][\_id]}"  
> }

But i can't get **id**. What wrong?

Maybe there is another way get \_id in previous doc in logstash?

---

<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:** [May 31, 2019, 2:32pm UTC](https://discuss.elastic.co/t/get-id-document-on-query/183732/2 "2019-05-31T14:32:50Z")

</div>

> [@pr0b3l](#):
>
> Maybe there is another way get \_id in previous doc in logstash?

If you are using an elasticsearch input you can use the docinfo option to have the input add the document id to each event.

---

<div class="post-metadata">

**Author:** ![pr0b3l](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pr0b3l](https://discuss.elastic.co/u/pr0b3l)\
**Post date:** [June 3, 2019, 1:51pm UTC](https://discuss.elastic.co/t/get-id-document-on-query/183732/4 "2019-06-03T13:51:24Z")

</div>

No, i'm not use input elasticsearch.

---

<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 1, 2019, 1:51pm UTC](https://discuss.elastic.co/t/get-id-document-on-query/183732/5 "2019-07-01T13:51:32Z")

</div>

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