# Can an ID of an index be not null but empty?

**URL:** https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167
**Category:** Elasticsearch
**Created:** [January 13, 2023, 11:39pm UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167 "2023-01-13T23:39:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Java2avaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/java2avaj/32/99497_2.png) [@Java2avaj](https://discuss.elastic.co/u/Java2avaj)
#### Post date: [January 13, 2023, 11:39pm UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167/1 "2023-01-13T23:39:39Z")

</div>

Just a question if by default, an id of an index be empty string value “”? If yes, how to prevent from saving an empty id?

---

<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: [January 14, 2023, 1:58am UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167/2 "2023-01-14T01:58:02Z")

</div>

What do you mean by id of an index exactly?

---

<div class="post-metadata">

### Author: ![Java2avaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/java2avaj/32/99497_2.png) [@Java2avaj](https://discuss.elastic.co/u/Java2avaj)
#### Post date: [January 14, 2023, 4:03am UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167/3 "2023-01-14T04:03:08Z")

</div>

Thanks for your reply. The “id”/“\_id” field. Can we store a document with empty id? If yes, how to prevent it?

---

<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: [January 14, 2023, 11:46am UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167/4 "2023-01-14T11:46:05Z")

</div>

No, the `_id` can not be empty.

Have you tested it? You can test with the following.

```auto
POST test-index/_bulk
{ "index" : { "_index" : "test-index", "_id" : "" } }
{ "field1" : "value1" }

```

The response will be:

```auto
{
  "took": 186,
  "errors": true,
  "items": [
    {
      "index": {
        "_index": "test-index",
        "_id": "",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "if _id is specified it must not be empty"
        }
      }
    }
  ]
}

```

---

<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: [February 11, 2023, 11:46am UTC](https://discuss.elastic.co/t/can-an-id-of-an-index-be-not-null-but-empty/323167/5 "2023-02-11T11:46:14Z")

</div>

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