# How to generate \_id field manually

**URL:** <https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302>\
**Category:** Logstash\
**Created:** [July 8, 2020, 8:47am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302 "2020-07-08T08:47:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![onkark](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@onkark](https://discuss.elastic.co/u/onkark)\
**Post date:** [July 8, 2020, 8:47am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/1 "2020-07-08T08:47:10Z")

</div>

I have imported a data of 3.5 crore documents in elasticsearch by using logstash. After I found that the unique field "\_id" is not generated. Now, I want to generate the unique field as "\_id" on all the documents. Can anyone help me ?

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 8, 2020, 9:18am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/2 "2020-07-08T09:18:00Z")

</div>

If your events have a field that you want to use as the \_id in Elasticsearch, you'll have to configure the [document\_id](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-document_id) in your output as `"%{your_field_with_a_unique_value_per_document}"`. If you do not already have a field that you can use as an ID, you can either use the ID that ES generates automatically or build a [fingerprint](https://www.elastic.co/guide/en/logstash/current/plugins-filters-fingerprint.html) based on some fields of your document.

---

<div class="post-metadata">

**Author:** ![onkark](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@onkark](https://discuss.elastic.co/u/onkark)\
**Post date:** [July 9, 2020, 7:33am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/3 "2020-07-09T07:33:03Z")

</div>

Thanks @Jenni for your reply but the issue is that ES hasn't generated any ID for the documents i have imported through logstash. I didn't have any unique field in the data. So, I need to create an unique field. What should I do in this case ?

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 9, 2020, 8:09am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/4 "2020-07-09T08:09:39Z")

</div>

It's impossible to have documents without an \_id in Elasticsearch. Why do you think there is none?

---

<div class="post-metadata">

**Author:** ![onkark](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@onkark](https://discuss.elastic.co/u/onkark)\
**Post date:** [July 9, 2020, 9:53am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/5 "2020-07-09T09:53:03Z")

</div>

Because when I checked the mappings, it is not showing me any field like \_id or simply ID. The extra fields that ES created are version, timestamp, path and host.

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 9, 2020, 9:56am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/6 "2020-07-09T09:56:52Z")

</div>

The \_id is a [meta-field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-fields.html) and won't show up in the field mappings. But if you look at your data in Kibana Discover, you'll see that each document has an \_id.

---

<div class="post-metadata">

**Author:** ![onkark](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@onkark](https://discuss.elastic.co/u/onkark)\
**Post date:** [July 9, 2020, 10:19am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/7 "2020-07-09T10:19:02Z")

</div>

I got it. But when I sent a request like

GET \_sql{  
"query" : " select \_id from index "  
}

then the response is like

Unknown column [\_id].

This scenario is only for the indexes I imported through logstash.

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 9, 2020, 10:24am UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/8 "2020-07-09T10:24:02Z")

</div>

This is a constraint of SQL:

> [@Is there a way to access internal \_id and \_type fields in ES SQL query (XPack)?](https://discuss.elastic.co/t/is-there-a-way-to-access-internal-id-and-type-fields-in-es-sql-query-xpack/174894/2):
>
> Hi @j_bennet, Indeed, this is not possible. The reason is that in SQL, an user is able to search for columns (fields) that they know about and that they actually inserted in Elasticsearch. But the \_id and the \_type are not fields/columns that you actually put in an index, this is more like meta information. And we bypass these fields in ES SQL by default. For \_id we have a [github issue](https://github.com/elastic/elasticsearch/issues/30266) created, but it's not on a concrete roadmap at the moment. Also, if I may, I'd like to comment on a stateme…

---

<div class="post-metadata">

**Author:** ![onkark](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@onkark](https://discuss.elastic.co/u/onkark)\
**Post date:** [July 9, 2020, 12:06pm UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/9 "2020-07-09T12:06:32Z")

</div>

Ok. Thanks for making it clear to me.

---

<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:** [August 6, 2020, 12:06pm UTC](https://discuss.elastic.co/t/how-to-generate-id-field-manually/240302/10 "2020-08-06T12:06:33Z")

</div>

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