# searchSourceBuilder fetchSource flag doesn't work for aggregation responses

**URL:** <https://discuss.elastic.co/t/searchsourcebuilder-fetchsource-flag-doesnt-work-for-aggregation-responses/174482>\
**Category:** Elasticsearch\
**Created:** [March 29, 2019, 6:59am UTC](https://discuss.elastic.co/t/searchsourcebuilder-fetchsource-flag-doesnt-work-for-aggregation-responses/174482 "2019-03-29T06:59:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shankar\_Daruga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shankar_daruga/32/34891_2.png) [@Shankar\_Daruga](https://discuss.elastic.co/u/Shankar_Daruga)\
**Post date:** [March 29, 2019, 6:59am UTC](https://discuss.elastic.co/t/searchsourcebuilder-fetchsource-flag-doesnt-work-for-aggregation-responses/174482/1 "2019-03-29T06:59:44Z")

</div>

Hi,

We are using searchSourceBuilder to create queries. We have source enabled in our mapping and we've tried setting the searchSourceBuilder.fetchSource(false) in our client code. It works fine for normal search requests. However, when we give an aggregation query, the \_source is returned.

We have code something like below :

```
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(query) // query is already built
searchSourceBuilder.aggregation(agg) // agg is also built seperately.
searchSourceBuilder.fetchSource(false)
SearchRequest searchRequest = new SearchRequest();
client.search(searchRequest, RequestOptions.DEFAULT) //Our client is REST High Level Client

```

I'm not sure if this expected that aggregation would always return \_source field or a bug.

Client Jar we are using is elasticsearch-6.6.0

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:** [April 26, 2019, 6:59am UTC](https://discuss.elastic.co/t/searchsourcebuilder-fetchsource-flag-doesnt-work-for-aggregation-responses/174482/2 "2019-04-26T06:59:49Z")

</div>

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