# How to create a document where the \_id has spaces (Dev Tools)

**URL:** <https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404>\
**Category:** Elasticsearch\
**Created:** [November 3, 2023, 7:46pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404 "2023-11-03T19:46:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thadc](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@thadc](https://discuss.elastic.co/u/thadc)\
**Post date:** [November 3, 2023, 7:46pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/1 "2023-11-03T19:46:41Z")

</div>

I am attempting to create a document in an index where \_id has spaces. I get a parsing exception in Dev Tools. Here is the start of POST statement:

POST /label-expression/\_doc/(AB\_123 | CD\_123)

I must have the spaces, and somehow all the other documents in the index have \_ids with spaces. I tried escaping like this:

POST /label-expression/\_doc/(AB\_123\ |\ \CD\_123)

, still got error. I would be grateful for any ideas, even if I have to do it some other way than with Dev Tools. Thank you!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 3, 2023, 8:14pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/2 "2023-11-03T20:14:52Z")

</div>

May be replace spaces with %20?

---

<div class="post-metadata">

**Author:** ![bunste](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bunste/32/95865_2.png) [@bunste](https://discuss.elastic.co/u/bunste)\
**Post date:** [November 4, 2023, 7:39am UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/3 "2023-11-04T07:39:51Z")

</div>

And you have to use the PUT verb (instead of POST) when you want to specify an id during document creation.

---

<div class="post-metadata">

**Author:** ![thadc](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@thadc](https://discuss.elastic.co/u/thadc)\
**Post date:** [November 4, 2023, 12:16pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/4 "2023-11-04T12:16:12Z")

</div>

Yes! that worked! Thank you sir!!

---

<div class="post-metadata">

**Author:** ![thadc](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@thadc](https://discuss.elastic.co/u/thadc)\
**Post date:** [November 4, 2023, 12:17pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/5 "2023-11-04T12:17:08Z")

</div>

Really?? Its working fine with POST

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2023, 12:36pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/6 "2023-11-04T12:36:01Z")

</div>

But it should be a PUT indeed.

---

<div class="post-metadata">

**Author:** ![thadc](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@thadc](https://discuss.elastic.co/u/thadc)\
**Post date:** [November 4, 2023, 1:09pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/7 "2023-11-04T13:09:48Z")

</div>

ok regarding PUT. What is the down side of using POST instead of PUT in this situation?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2023, 2:28pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/8 "2023-11-04T14:28:07Z")

</div>

POST should not work as in that case the id is automatically generated.

PUT means put this specific resource (knowing its id)

---

<div class="post-metadata">

**Author:** ![bunste](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bunste/32/95865_2.png) [@bunste](https://discuss.elastic.co/u/bunste)\
**Post date:** [November 4, 2023, 3:05pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/9 "2023-11-04T15:05:51Z")

</div>

Actually, both PUT and POST work. I really thought that you had to use PUT in this case - that's also what it says in the current [Index API docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html).

Just tested the following with Kibana Dev Tools (ELK Stack v8.10.4)

```auto
POST /products/_doc/76
{
  "name": "Laptop"
}

PUT /products/_doc/42
{
  "name": "Book"
}

# Both products have the specified _id
GET /products/_search

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2023, 10:08pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/10 "2023-11-04T22:08:45Z")

</div>

Agreed. It looks like a bug or a undocumented change... 😊

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

---

<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:** [December 2, 2023, 10:09pm UTC](https://discuss.elastic.co/t/how-to-create-a-document-where-the-id-has-spaces-dev-tools/346404/11 "2023-12-02T22:09:42Z")

</div>

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