# Aggregration through Java High Level Rest Client

**URL:** <https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184>\
**Category:** Elasticsearch\
**Created:** [January 19, 2018, 8:28am UTC](https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184 "2018-01-19T08:28:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 19, 2018, 8:28am UTC](https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184/1 "2018-01-19T08:28:43Z")

</div>

I need to perform aggregations on multiple index through Java.

```
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9200,"http")));
		
		SearchRequest searchRequest = new SearchRequest();
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.query(QueryBuilders.matchAllQuery()).aggregation(AggregationBuilders.avg("expenditure_avg").field("expenditure"));
		searchRequest.source(searchSourceBuilder);
		SearchResponse searchResponse = client.search(searchRequest);
	
		
		System.out.println(searchResponse.toString());

```

I have tried the above but dont know how to perform the same on multiple Index.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 19, 2018, 9:30am UTC](https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184/2 "2018-01-19T09:30:53Z")

</div>

From the code you pasted, you are already running that on all indices.

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 19, 2018, 11:50am UTC](https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184/3 "2018-01-19T11:50:56Z")

</div>

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:** [February 16, 2018, 11:52am UTC](https://discuss.elastic.co/t/aggregration-through-java-high-level-rest-client/116184/4 "2018-02-16T11:52:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
