# Documents not editable of index

**URL:** <https://discuss.elastic.co/t/documents-not-editable-of-index/337307>\
**Category:** Kibana\
**Created:** [June 30, 2023, 11:20am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307 "2023-06-30T11:20:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [June 30, 2023, 11:20am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/1 "2023-06-30T11:20:49Z")

</div>

```auto
PUT /your-index/_settings
{
  "index.blocks.write": true
} not working

```

---

<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:** [June 30, 2023, 12:10pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/2 "2023-06-30T12:10:12Z")

</div>

Hello and welcome,

You need to provide some context about your issue, it is not possible what you want to do and what is not working.

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [June 30, 2023, 1:16pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/3 "2023-06-30T13:16:31Z")

</div>

How To achieve the desired behavior where the Elasticsearch index is not mutable (documents cannot be modified), but new documents can still be inserted

so i try to `PUT /your_index { "settings": { "index.blocks.write": true } } `

but it's give an error `{ "error" : { "root_cause" : [{ "type" : "cluster_block_exception", "reason" : "index [your_index] blocked by: [FORBIDDEN/8/index write (api)];" } ], "type" : "cluster_block_exception", "reason" : "index [your_index] blocked by: [FORBIDDEN/8/index write (api)];" }, "status" : 403 }`

I'm the superuser and elasticsearch version is greter than 7.0

---

<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:** [June 30, 2023, 1:27pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/4 "2023-06-30T13:27:08Z")

</div>

> [@Jay\_Desai](#):
>
> How To achieve the desired behavior where the Elasticsearch index is not mutable (documents cannot be modified), but new documents can still be inserted

Are you using custom ids? You will need to use custom unique ids when indexing and depending on what you are using to send data to Elasticsearch it will reject the document if it already exists a document with the same id.

How are you indexing your data and what does your data looks like?

> [@Jay\_Desai](#):
>
> so i try to `PUT /your_index { "settings": { "index.blocks.write": true } }`

This blocks writing to the entire index, if you set this on an index no data can be indexed anymore.

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [June 30, 2023, 1:32pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/5 "2023-06-30T13:32:43Z")

</div>

I'm doing first step 👎  
PUT /your\_index  
{  
"settings": {  
"index.blocks.write": true  
}  
}

I'm doing second step :-2:  
POST /your\_index/\_doc  
{  
"field1": "value1",  
"field2": "value2"  
}

and it's give me an error of `{ "error" : { "root_cause" : [{ "type" : "cluster_block_exception", "reason" : "index [your_index] blocked by: [FORBIDDEN/8/index write (api)];" } ], "type" : "cluster_block_exception", "reason" : "index [your_index] blocked by: [FORBIDDEN/8/index write (api)];" }, "status" : 403 }`

---

<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:** [June 30, 2023, 1:37pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/6 "2023-06-30T13:37:35Z")

</div>

As I said here:

> [@leandrojmp](#):
>
> This blocks writing to the entire index, if you set this on an index no data can be indexed anymore.

If you want to **write** on the index you **cannot** set `index.blocks.write` as true, as the name says it blocks any writing to that indice.

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [June 30, 2023, 1:41pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/7 "2023-06-30T13:41:23Z")

</div>

> [@Jay\_Desai](#):
>
> PUT /your\_index  
> {  
> "settings": {  
> "index.blocks.write": true  
> }

can you suggest me what i should be doing for achieve my problem?

---

<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:** [June 30, 2023, 3:37pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/8 "2023-06-30T15:37:04Z")

</div>

> [@Jay\_Desai](#):
>
> can you suggest me what i should be doing for achieve my problem?

It is not clear what is your problem now, but part of it was already answered in my previous post:

> You will need to use custom unique ids when indexing and depending on what you are using to send data to Elasticsearch it will reject the document if it already exists a document with the same id.

You need to provide more information about how you are indexing your data, how it looks like and what you want to do.

To have immutable documents without duplicating the data you need to use custom ids.

If you want to remove the `index.blocks.write` just do this request:

```auto
PUT /your_index
{
"settings": {
"index.blocks.write": false
}

```

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [July 3, 2023, 4:54am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/9 "2023-07-03T04:54:04Z")

</div>

I need of Elasticsearch Index functionality like insertion of document should be allowed in index. but those document which is inserting in index should not editable or not removable.

---

<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:** [July 3, 2023, 5:04am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/10 "2023-07-03T05:04:51Z")

</div>

> [@Jay\_Desai](#):
>
> I need of Elasticsearch Index functionality like insertion of document should be allowed in index. but those document which is inserting in index should not editable or not removable.

As mentioned in previous answers you need to use custom documents ids for this to work.

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [July 3, 2023, 5:18am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/11 "2023-07-03T05:18:45Z")

</div>

Yes i got your point,

As now we adding documents in index using custom ids.  
ex :-

{  
"\_index" : "txn\_master",  
"\_type" : "\_doc",  
"\_id" : "b6947042d82c4ae1b40d92aa1783a2ef",  
"\_score" : 6.788873,  
"\_source" : {  
"id" : "b6947042d82c4ae1b40d92aa1783a2ef",  
"txn\_number" : "48007269"  
}  
}

But it's adding on index there immutability not handle

---

<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:** [July 3, 2023, 5:34am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/12 "2023-07-03T05:34:58Z")

</div>

> [@Jay\_Desai](#):
>
> But it's adding on index there immutability not handle

How are you adding the documents?

As already mentioned on a previous answer:

> You will need to use custom unique ids when indexing and depending on what you are using to send data to Elasticsearch it will reject the document if it already exists a document with the same id.

If you make a request to Elasticsearch for a document with a custom id that already exists in the same index, Elasticsearch may **update** or **reject** the request depending on how you are indexing it.

If you want Elasticsearch to reject it, you will need to set the `op_type` to `create` while making the request.

How you will do that depends entirely on how you are indexing your data, which you didn't provide any context.

You can read more on the [Index API documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html) and on the [Bulk API documentation](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-bulk.html#docs-bulk-api-desc).

---

<div class="post-metadata">

**Author:** ![Jay\_Desai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_desai/32/121787_2.png) [@Jay\_Desai](https://discuss.elastic.co/u/Jay_Desai)\
**Post date:** [July 4, 2023, 4:36am UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/13 "2023-07-04T04:36:41Z")

</div>

Yes i'm using op\_type=create for try to insert the document in index but when i updating it's updatable..

PUT your\_index\_name/\_doc/1?op\_type=create  
{  
"your\_field": "Your document content",  
"version": 1  
}

PUT your\_index\_name/\_doc/1  
{  
"your\_field": "Updated document content",  
"version": 2  
}

so the it's output of "your\_field" : "Updated document content"

---

<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:** [July 4, 2023, 12:37pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/14 "2023-07-04T12:37:55Z")

</div>

In your second request you didn't use `op_type` as `create`, you need to use it in **every** request.

Since your second request does not have the `op_type` set to `create`, Elasticsearch will use the `op_type` as `index`, and this will update your document.

With `op_type` as `create` in your second request, the request will return the following error:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "version_conflict_engine_exception",
        "reason": "[1]: version conflict, document already exists (current version [1])",
        "index_uuid": "K69nKut7RcytGKuKu13kAA",
        "shard": "0",
        "index": "your_index_name"
      }
    ],
    "type": "version_conflict_engine_exception",
    "reason": "[1]: version conflict, document already exists (current version [1])",
    "index_uuid": "K69nKut7RcytGKuKu13kAA",
    "shard": "0",
    "index": "your_index_name"
  },
  "status": 409
}

```

---

<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:** [August 1, 2023, 12:38pm UTC](https://discuss.elastic.co/t/documents-not-editable-of-index/337307/15 "2023-08-01T12:38:20Z")

</div>

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