Hi,
I am using the ES 1.4.2 version and associated Java API. I see bug with ES for the Upsert script.
The Upsert operation is unable to set "_parent" for Child doc types.
Here I use the below Upsert script for inserting/updating the child doc of type "tag". The "tag" mapping has the parent "userinfo" mapping. I use "userId" in "UserInfo" mapping as its "_id". The "tag" type uses the same as "_parent".
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.field("eventDate", sdf.format(tagObj.getEventDate()))
.field("manufacturer", tagObj.getManufacturer())
.field("applicationId", tagObj.getApplicationId())
.field("count", tagObj.getEventCount())
.field("tag", tagObj.getEventName())
.endObject();
logger.info("About to insert/update index for tag :" + builder.string());
bulkBuilder.add(esClient
.prepareUpdate("users", "tag", tagObj.getId())
.setScript("ctx._source.eventDate = \""+sdf.format(tagObj.getEventDate())
+"\";ctx._source.count += "+tagObj.getEventCount()
+";ctx._source.country = \""+tagObj.getCountry()+"\"")
.setUpsert(builder)
.setParent(Long.toString(tagObj.getUserId()))
.setRouting(Long.toString(tagObj.getUserId())));
Here this Upsert script inserts the "tag" doc but doesn't set the "_parent" field.
The same was working with the Insert script given below. The "_parent" was getting set in "tag" doc.
bulkBuilder.add(esClient.prepareIndex("users", "tag", tagObj.getId())
.setSource(builder.string())
.setParent(Long.toString(tagObj.getUserId()))
.setRouting(Long.toString(tagObj.getUserId())));
Why is the Upsert operation having this issue.
Thanks
Suman