# Custom id when inserting a document in existing index

**URL:** <https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352>\
**Category:** Kibana\
**Created:** [August 31, 2022, 11:40am UTC](https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352 "2022-08-31T11:40:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kibanauser4](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kibanauser4](https://discuss.elastic.co/u/kibanauser4)\
**Post date:** [August 31, 2022, 11:40am UTC](https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352/1 "2022-08-31T11:40:22Z")

</div>

I am using Dev tools in Kibana to insert a new document in an existing index. But I can't figure out if I can set the \_id field to a custom value. Is there a way to do this?  
This is what I'm doing now:

```auto
POST user/_doc/1
{
  "name" : "John Doe",
  "licenseId" : "XXXXX",
   "age": 20
}

```

I want to somehow set the \_id field too in this query.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [August 31, 2022, 12:12pm UTC](https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352/2 "2022-08-31T12:12:13Z")

</div>

It is explained in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#docs-index-api-request).

> `PUT /<target>/_doc/<_id>`

In your request, the id is what cames after `_doc/`, so if you are using `1`, the `_id` of the document will be `1`.

If you want to set a custom id in a request like that you need to use PUT and set your custom `_id` after `_doc`.

```auto
PUT user/_doc/your-custom-id
{
  "name" : "John Doe",
  "licenseId" : "XXXXX",
   "age": 20
}

```

---

<div class="post-metadata">

**Author:** ![kibanauser4](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kibanauser4](https://discuss.elastic.co/u/kibanauser4)\
**Post date:** [August 31, 2022, 12:13pm UTC](https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352/3 "2022-08-31T12:13:02Z")

</div>

Oooh I completely missed that, thank you!

---

<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:** [September 28, 2022, 12:13pm UTC](https://discuss.elastic.co/t/custom-id-when-inserting-a-document-in-existing-index/313352/4 "2022-09-28T12:13:05Z")

</div>

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