# How to return document id from sql query?

**URL:** <https://discuss.elastic.co/t/how-to-return-document-id-from-sql-query/147129>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [September 4, 2018, 2:23am UTC](https://discuss.elastic.co/t/how-to-return-document-id-from-sql-query/147129 "2018-09-04T02:23:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongyuan1306](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hongyuan1306/32/34868_2.png) [@hongyuan1306](https://discuss.elastic.co/u/hongyuan1306)\
**Post date:** [September 4, 2018, 2:23am UTC](https://discuss.elastic.co/t/how-to-return-document-id-from-sql-query/147129/1 "2018-09-04T02:23:42Z")

</div>

Is there a way to return the document id from the `SELECT` sql query? I tried to use \_id, but got `Unknown column [_id]`

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [September 4, 2018, 3:36am UTC](https://discuss.elastic.co/t/how-to-return-document-id-from-sql-query/147129/2 "2018-09-04T03:36:31Z")

</div>

Hey @hongyuan1306,  
At the moment this is not possible, unless you have an explicit regular field defined as ID.  
But, there is an issue open for considering this as an enhancement: [https://github.com/elastic/elasticsearch/issues/30266](https://github.com/elastic/elasticsearch/issues/30266)

---

<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:** [October 2, 2018, 3:36am UTC](https://discuss.elastic.co/t/how-to-return-document-id-from-sql-query/147129/3 "2018-10-02T03:36:33Z")

</div>

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