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

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?

What do you mean by id of an index exactly?

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

No, the _id can not be empty.

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

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

The response will be:

  "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"
1 Like

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