# Elasticsearch json response to SearchResponse object

**URL:** <https://discuss.elastic.co/t/elasticsearch-json-response-to-searchresponse-object/124394>\
**Category:** Elasticsearch\
**Created:** [March 17, 2018, 9:20am UTC](https://discuss.elastic.co/t/elasticsearch-json-response-to-searchresponse-object/124394 "2018-03-17T09:20:06Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [March 17, 2018, 11:15am UTC](https://discuss.elastic.co/t/elasticsearch-json-response-to-searchresponse-object/124394/4 "2018-03-17T11:15:42Z")

</div>

As far as I can read the code

> <https://github.com/elastic/elasticsearch/blob/6.x/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java#L245-L249>

It looks like `innerFromXContent` is also parsing the aggs part.

> <https://github.com/elastic/elasticsearch/blob/6.x/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java#L288-L289>

This is calling:

> <https://github.com/elastic/elasticsearch/blob/6.x/server/src/main/java/org/elasticsearch/search/aggregations/Aggregations.java#L134-L152>

Behind the scene this needs to know what kind of aggregation you asked for, what is the java type to use. The magic is happening here:

> <https://github.com/elastic/elasticsearch/blob/6.x/server/src/main/java/org/elasticsearch/common/xcontent/XContentParserUtils.java#L122-L161>

So you need to add a prefix like `terms#` if you are getting back a terms aggregation.

`terms#foo` as the javadoc example says.

I hope this can help.

---

_[View the full topic](https://discuss.elastic.co/t/elasticsearch-json-response-to-searchresponse-object/124394)._
