# Data loss in bulk update for field type date using painless script

**URL:** <https://discuss.elastic.co/t/data-loss-in-bulk-update-for-field-type-date-using-painless-script/265761>\
**Category:** Elasticsearch\
**Created:** [March 1, 2021, 7:16am UTC](https://discuss.elastic.co/t/data-loss-in-bulk-update-for-field-type-date-using-painless-script/265761 "2021-03-01T07:16:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manjunath\_Kadrolli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manjunath_kadrolli/32/84703_2.png) [@Manjunath\_Kadrolli](https://discuss.elastic.co/u/Manjunath_Kadrolli)\
**Post date:** [March 1, 2021, 7:16am UTC](https://discuss.elastic.co/t/data-loss-in-bulk-update-for-field-type-date-using-painless-script/265761/1 "2021-03-01T07:16:01Z")

</div>

Following is a row from my bulk update http body  
When i run the same for small set of records (100) the same works fine but if i trigger the for the entire DB the the valueTimestamp field always null where other values are updated fine.

{"update" :{"\_index":"masterdata","\_type":"\_doc","\_id":"6.50"}}  
{"script" : {"lang":"painless","source": "if (!ctx.\_source.containsKey("assignedAttributes") &&  
params.assignedAttributes != null && params.assignedAttributes.attributeId != null )  
{ctx.\_source["assignedAttributes"] = new ArrayList(); }  
if( params.assignedAttributes != null && params.assignedAttributes.attributeId != null )  
{ int num = -1; for (int i =0; i = ctx.\_source.assignedAttributes.size(); i++)  
{ if (ctx.\_source.assignedAttributes.get(i).attributeId != null && ctx.\_source.assignedAttributes.get(i).attributeId == params.assignedAttributes.attributeId )  
{ num= i; break; } } if (num == -1)  
{ ctx.\_source.assignedAttributes.add(params.assignedAttributes); return; }  
else { ctx.\_source.assignedAttributes.set(num, params.assignedAttributes); } }  
if(!ctx.\_source.containsKey("assignedAttributes"))  
{ ctx.\_source.assignedAttributes = params.assignedAttributes; }","params":{"companyId":6,"customerId":50,"assignedAttributes":{"customerAttributeId":20391484,"attributeId":220,"valueDataType":"timestamp","valueTimestamp":["2021-02-09"]}}}}

mapping :  
"mappings": {  
"properties": {  
"assignedAttributes": {  
"type": "nested",  
"dynamic": "false",  
"properties": {  
"attributeId": {  
"type": "long",  
"null\_value": -999999  
},  
"customerAttributeId": {  
"type": "long"  
},  
"dataType": {  
"type": "text"  
},  
"valueBoolean": {  
"type": "boolean",  
"null\_value": false  
},  
"valueDataType": {  
"type": "text"  
},  
"valueDouble": {  
"type": "double",  
"null\_value": -999999.0  
},  
"valueLong": {  
"type": "long",  
"null\_value": -999999  
},  
"valueText": {  
"type": "keyword",  
"null\_value": "NULL"  
},  
"valueTimestamp": {  
"type": "date",  
"format": "yyyy-MM-dd"  
}  
}  
},  
"companyId": {  
"type": "long"  
},  
"customerId": {  
"type": "long"  
}  
}  
}

---

<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:** [March 29, 2021, 7:16am UTC](https://discuss.elastic.co/t/data-loss-in-bulk-update-for-field-type-date-using-painless-script/265761/2 "2021-03-29T07:16:29Z")

</div>

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