# How to create the perfect \_id by my own?

**URL:** <https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757>\
**Category:** Elasticsearch\
**Created:** [February 17, 2019, 10:56pm UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757 "2019-02-17T22:56:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [February 17, 2019, 10:56pm UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/1 "2019-02-17T22:56:56Z")

</div>

Hey,

I must create my own \_id field.  
This id is basically a combination of 5 other fields of a document, so for example:

```
   {
       "a": 100,
       "b": "CUSTOM_TYPE",
       "c": 300,
       "d": "bla"
       "e": "foo",
       "value": " 42
    }

```

So my key is basically: "100\_CUSTOM\_TYPE\_300\_bla\_foo" which is a very bad none sortable and none compressed key, but it is my key. I thought about just doing an md5 on it and use the result, but I am not sure if this is the optimal solution.  
I looked at how Elasticsearch implemented the id generation, which is based on flake ids, which are time-based, but this is not my case.

Any idea?  
Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 17, 2019, 11:04pm UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/2 "2019-02-17T23:04:24Z")

</div>

> [@tpraizler](#):
>
> I must create my own \_id field.

Can you clarify why?

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [February 17, 2019, 11:17pm UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/3 "2019-02-17T23:17:39Z")

</div>

Sure, I need to index the same document, essentially update the same one.  
I load my data from S3, and index it to Elastic. While those ids are already referenced by other entities in the system. The document in S3 must already contain the id before it is being indexed.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 17, 2019, 11:19pm UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/4 "2019-02-17T23:19:36Z")

</div>

Ok then, so what's the problem with your existing id approach? You don't really want to sort on it, compressibility would also be less than ideal for the default auto-generated id as well.

I'd just keep what you have.

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [February 18, 2019, 7:26am UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/5 "2019-02-18T07:26:29Z")

</div>

Great thanks!

---

<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:** [March 18, 2019, 7:26am UTC](https://discuss.elastic.co/t/how-to-create-the-perfect-id-by-my-own/168757/6 "2019-03-18T07:26:31Z")

</div>

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