Bulk script update issue


(ada) #1

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,


(system) #2