Adding arrays of objects using java update API and scripting

How do I use updateRequestBuilder.addScriptParam to add List/Arrays.

I want to replace "ctx._source.communities" with the list of maps called
"new_communities" but it always ends up as an empty array.

List<Map<String,Object>> communityMapList = new

        for(CommunityRelationship community : 


            Map<String,Object> communityMap = new


            communityMap.put("communityId", community.getCommunityId());






        UpdateRequestBuilder updateRequestBuilder = client

.prepareUpdate(SearchFields.INDEX, SearchFields.USER_TYPE, userId)

                .addScriptParam("new_communities", communityMapList)



                .setScript("ctx._source.communities = new_communities");

I've figured out how to pass in a single community append but I'd really
like to pass in a list of communities.

This seems a simple thing to do using json (Just write out the string
but I can't see how to pass this into the java api.

Any ideas?


You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit