# Adding arrays of objects using java update API and scripting

**URL:** <https://discuss.elastic.co/t/adding-arrays-of-objects-using-java-update-api-and-scripting/15474>\
**Category:** Elasticsearch\
**Created:** [January 29, 2014, 1:19pm UTC](https://discuss.elastic.co/t/adding-arrays-of-objects-using-java-update-api-and-scripting/15474 "2014-01-29T13:19:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Wilson\_Mawer](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@Luke\_Wilson\_Mawer](https://discuss.elastic.co/u/Luke_Wilson_Mawer)\
**Post date:** [January 29, 2014, 1:19pm UTC](https://discuss.elastic.co/t/adding-arrays-of-objects-using-java-update-api-and-scripting/15474/1 "2014-01-29T13:19:30Z")

</div>

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  
ArrayList\<Map\<String,Object\>\>();

```
        for(CommunityRelationship community : 

```

communitiesByTwitterUser.get(userId)){

```
            Map<String,Object> communityMap = new

```

HashMap\<String,Object\>();

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

            communityMap.put("communityName", 

```

community.getCommunityName());

```
            communityMapList.add(communityMap);

        }           

        

        UpdateRequestBuilder updateRequestBuilder = client

```

.prepareUpdate(SearchFields.INDEX, SearchFields.USER\_TYPE, userId)

```
                .addScriptParam("new_communities", communityMapList)

                .setConsistencyLevel(WriteConsistencyLevel.ALL)

                .setRetryOnConflict(10)

                .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  
[{"communityId":32,"communityName":"lukes\_community"},[{"communityId":33,"communityName":"bills\_community"}]  
but I can't see how to pass this into the java api.

Any ideas?

Luke

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e48362ad-e7d2-48df-ae3c-02c0ad867b3c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e48362ad-e7d2-48df-ae3c-02c0ad867b3c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 1:54am UTC](https://discuss.elastic.co/t/adding-arrays-of-objects-using-java-update-api-and-scripting/15474/2 "2017-07-06T01:54:12Z")

</div>


