Documents not editable of index

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

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.

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

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?

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

I'm doing first step :-1:
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 }

As I said here:

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.

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:

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

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.

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

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 and on the Bulk API documentation.

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"

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:

{
  "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
}

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