# Querying elasticsearch for doc id

**URL:** https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669
**Category:** Logstash
**Created:** [March 7, 2016, 3:25pm UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669 "2016-03-07T15:25:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)
#### Post date: [March 7, 2016, 3:25pm UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669/1 "2016-03-07T15:25:29Z")

</div>

Hi all,

I have logstash configuration and I'm trying to get the "\_id" of a document that answer to some terms (using elasticsearch filter)

**for example:**  
i did a grok filter and now i have values for testA and testB and i want to see if i already index it if i did i want to do something (the point is getting the id)

query =\> "type:test AND testA:%{testA} AND testB:%{testB}"   
here I have (or haven't) the doc with this details but can't get the id of it

---

<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: [March 7, 2016, 6:23pm UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669/2 "2016-03-07T18:23:20Z")

</div>

See if you can use the [elasticsearch filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-elasticsearch.html). A more efficient way would be to generate the id based on certain field values. Then you don't have to check for the existence of the correct document, you can just index the current document which then may or may not overwrite the existing one.

---

<div class="post-metadata">

### Author: ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)
#### Post date: [March 8, 2016, 6:12am UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669/3 "2016-03-08T06:12:38Z")

</div>

@magnusbaeck I am using the es filter but i can't get from the query the \_id of the doc so when i will do 'update' action on es output i will have the specific id to use.

how i can get the \_id value using es filter?

---

<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: [March 8, 2016, 6:31am UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669/4 "2016-03-08T06:31:40Z")

</div>

Ah. Yes, I guess the id isn't available in the source document itself and therefore isn't made available through this plugin. It seems reasonable to be able to obtain the id of matching documents, though. Feel free to file a GitHub issue: [https://github.com/logstash-plugins/logstash-filter-elasticsearch/issues/new](https://github.com/logstash-plugins/logstash-filter-elasticsearch/issues/new)

---

<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:08am UTC](https://discuss.elastic.co/t/querying-elasticsearch-for-doc-id/43669/5 "2017-07-06T05:08:04Z")

</div>


