# Update docs only when fields change and store time and content of update

**URL:** https://discuss.elastic.co/t/update-docs-only-when-fields-change-and-store-time-and-content-of-update/24385
**Category:** Elasticsearch
**Created:** [June 25, 2015, 11:18pm UTC](https://discuss.elastic.co/t/update-docs-only-when-fields-change-and-store-time-and-content-of-update/24385 "2015-06-25T23:18:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![twigbranch](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@twigbranch](https://discuss.elastic.co/u/twigbranch)
#### Post date: [June 25, 2015, 11:18pm UTC](https://discuss.elastic.co/t/update-docs-only-when-fields-change-and-store-time-and-content-of-update/24385/1 "2015-06-25T23:18:44Z")

</div>

I'm importing data periodically. Some of the documents are completely new, whereas others include modifications to only certain fields.

Using the bulk api, I'd like to be able to index the new documents, storing a created time. And, update the modified documents, only when fields have changed, storing at least an updated time and ideally, also, a record of what changed (so ultimately I could view revisions over time).

Is this possible? What would be the recommended way to do this?

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [June 26, 2015, 12:59am UTC](https://discuss.elastic.co/t/update-docs-only-when-fields-change-and-store-time-and-content-of-update/24385/2 "2015-06-26T00:59:06Z")

</div>

It's common. Usually you use a groovy script for the update. You can detect  
if there are changes, set the operation to noop if there aren't and set the  
last modified time if there are changes. You have to write the groovy for  
it. See the documentation for scripted updates.

The wikimedia-extra plugin supports some of what you are after in a  
declarative way with its super\_detect\_noop feature. Not the last modified  
time though.

Nik

---

<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: [July 6, 2017, 12:05am UTC](https://discuss.elastic.co/t/update-docs-only-when-fields-change-and-store-time-and-content-of-update/24385/3 "2017-07-06T00:05:20Z")

</div>


