# Preventing document field from getting updated in Elastic Search

**URL:** <https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300>\
**Category:** Elasticsearch\
**Created:** [May 26, 2020, 10:05am UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300 "2020-05-26T10:05:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![viralshah1494](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@viralshah1494](https://discuss.elastic.co/u/viralshah1494)\
**Post date:** [May 26, 2020, 10:05am UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/1 "2020-05-26T10:05:02Z")

</div>

I have the following requirement. In the system there is a job running that fetches the documents from another system every 15 mins. Once those documents are fetched, I have my own job which runs and updates the document and inserts some fields into it. Like the document which was fetched from another system is something like this.

```auto
{
  "id": 1,
  "firstName": "XYZ",
  "lastName": "ABC",
  "grade": "",
  "isUpdaterequired":"true",
  "details":{
    "firstName": null,
    "lastName": null,
    "grade": null,
    "otherDetails":null
  }
}

```

Now once this document is ingested then we run our own job and modifies the document like this:

```auto
{
  "id": 1,
  "firstName": "XYZ",
  "lastName": "ABC",
  "grade": "",
  "isUpdaterequired":false,
  "details":{
    "firstName": "XYZ",
    "lastName": "ABC",
    "grade": "1.10",
    "otherDetails":"Filled from some other source"
  }
}

```

Now after the 15 mins data fetch job runs again it gets the documents and the same document comes again

```auto
{
  "id": 1,
  "firstName": "XYZ",
  "lastName": "ABC",
  "grade": "",
  "isUpdaterequired":"true",
  "details":{
    "firstName": null,
    "lastName": null,
    "grade": null,
    "otherDetails":null
  }
}

```

So my job will save the document again and the "details" filed will be replaced. Can we prevent this specific field from getting updated using the `"isUpdaterequired"` field or is there any other way to stop updating a field in the time of upsert?

I am using an Elastic search with Spring boot.

Querying the presence of the document before every save is expensive as we received almost 10k documents at every 15 mins.

Thank you!!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 27, 2020, 5:45am UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/2 "2020-05-27T05:45:43Z")

</div>

That is something you will have to control from your application code. Elasticsearch has no way to enforce restrictions at the field level within a document.

---

<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:** [May 27, 2020, 10:05am UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/3 "2020-05-27T10:05:06Z")

</div>

For writes, yes.  
There is read level controls 🙂

---

<div class="post-metadata">

**Author:** ![viralshah1494](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@viralshah1494](https://discuss.elastic.co/u/viralshah1494)\
**Post date:** [May 27, 2020, 5:17pm UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/4 "2020-05-27T17:17:14Z")

</div>

Could you please give me some details about it or things to look in the elastic docs. That would be a great help.

---

<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:** [May 27, 2020, 9:52pm UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/5 "2020-05-27T21:52:36Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/reference/current/field-level-security.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/field-level-security.html)

---

<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:** [June 24, 2020, 9:52pm UTC](https://discuss.elastic.co/t/preventing-document-field-from-getting-updated-in-elastic-search/234300/6 "2020-06-24T21:52:37Z")

</div>

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