# Bulk script update issue

**URL:** https://discuss.elastic.co/t/bulk-script-update-issue/27626
**Category:** Elasticsearch
**Created:** [August 18, 2015, 11:42pm UTC](https://discuss.elastic.co/t/bulk-script-update-issue/27626 "2015-08-18T23:42:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![aday](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@aday](https://discuss.elastic.co/u/aday)
#### Post date: [August 18, 2015, 11:42pm UTC](https://discuss.elastic.co/t/bulk-script-update-issue/27626/1 "2015-08-18T23:42:17Z")

</div>

I want to update the field to be in "array" style as follow:

"modelIds": [  
"1",  
"2",  
"3",  
]

but if i use the following code:

```
		Set<String> models = pmMap.getModels(partId);
		Map<String, Object> scriptParams = Maps.newHashMap();
		scriptParams.put("models", models.toArray());
		bulkProcessor.add(new UpdateRequest("catalog", "part", partId).script(
			"if (ctx._source.modelIds != null) { ctx._source.modelIds += models; } else { ctx._source.modelIds = models;}")
				.scriptParams(scriptParams));

```

when ctx.\_source.modelIds is null, i get the answer I want:  
"modelIds": [  
"13032000934502473271",  
"13032000934502473780"  
]  
but when ctx.\_source.modelIds is not null, it gets this:  
"modelIds": [  
"13032000934502473271",  
"13032000934502473780",  
[  
"13032000934502473273",  
"13032000934502473783",  
]  
]

what should be used for the +=?

Thanks,

---

<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 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/bulk-script-update-issue/27626/2 "2017-07-05T23:55:08Z")

</div>


