# Autogenerate id of IndexRequest before sending it

**URL:** <https://discuss.elastic.co/t/autogenerate-id-of-indexrequest-before-sending-it/175177>\
**Category:** Elasticsearch\
**Created:** [April 3, 2019, 11:18am UTC](https://discuss.elastic.co/t/autogenerate-id-of-indexrequest-before-sending-it/175177 "2019-04-03T11:18:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rk201](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@rk201](https://discuss.elastic.co/u/rk201)\
**Post date:** [April 3, 2019, 11:18am UTC](https://discuss.elastic.co/t/autogenerate-id-of-indexrequest-before-sending-it/175177/1 "2019-04-03T11:18:15Z")

</div>

Hi,

I would like to have ids of indexed documents auto-generated, but also, I want to know the id before I'll send the request. The id is generated in IndexRequest.process(...) method, so it doesn't work for me. Can I safely use

org.elasticsearch.common.UUIDs.base64UUID();

and set the id manually? I ask because I see a field "autoGeneratedTimestamp" that is also being set during default id generation, and its getter has a comment that it "will return a positive value if the id was auto generated". If I generate the ID manually, it won't be true. Can I ignore it? Or maybe there is an another solution?

PS. I use Elasticsearch 6.4.0 (server and library).

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 3, 2019, 12:03pm UTC](https://discuss.elastic.co/t/autogenerate-id-of-indexrequest-before-sending-it/175177/2 "2019-04-03T12:03:42Z")

</div>

Elasticsearch distinguishes between IDs it's generated itself and IDs that came from elsewhere, because there are some slight optimisations it can perform if it knows it generated the IDs itself. The `autoGeneratedTimestamp` field is part of those optimisations. However it is completely safe to generate your own IDs as you describe.

---

<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:** [May 1, 2019, 12:03pm UTC](https://discuss.elastic.co/t/autogenerate-id-of-indexrequest-before-sending-it/175177/3 "2019-05-01T12:03:45Z")

</div>

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