# Unable to get Source filter while doing elastic search with spring boot class org.elasticsearch.search.builder.SearchSourceBuilder

**URL:** <https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640>\
**Category:** Elasticsearch\
**Created:** [October 1, 2020, 10:04am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640 "2020-10-01T10:04:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 1, 2020, 10:04am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/1 "2020-10-01T10:04:18Z")

</div>

This is the code Sample which i m using to get the result:-

```auto
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("contentsearch");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder bFilter = QueryBuilders.boolQuery();

@SuppressWarnings("unchecked")
Map<String,String> filterMap = (Map<String, String>) inputMap.get("Filter");
for (Map.Entry<String, String> entry : filterMap.entrySet()) {
	bFilter.filter(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery((String) entry.getKey(), ((String) entry.getValue()).toLowerCase())));
}
@SuppressWarnings("unchecked")
List<String> outParamList = (List<String>) inputMap.get("Out");
String[] arr = new String[outParamList.size()]; 
searchSourceBuilder.query(bFilter);
searchSourceBuilder.fetchSource(true).fetchSource((String[]) outParamList.toArray(arr),null);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
	searchResponse= esClient.search(searchRequest, RequestOptions.DEFAULT);
}catch (Exception e) {
	e.printStackTrace();		
}
if(searchResponse!=null) {	
	SearchHit[] searchHits = searchResponse.getHits().getHits();
	logger.info("Search hits total : "+searchResponse.getHits().getTotalHits().value);
	for (SearchHit hit:searchHits) {
		Map<String, Object> map = hit.getSourceAsMap();
		logger.info("map---"+map.toString());
		JSONObject jsonObject = new JSONObject(map);
		jsonArray.put(jsonObject);
	}
}

```

If we are not using this statement

searchSourceBuilder.fetchSource(true).fetchSource((String) outParamList.toArray(arr),null);

Than we are getting whole columns but i want specific source filter. So if anybody can help on this. It will be very kindly thankful to them.

Using HighLevelRestClient for this. Getting output in this form :  
map---{}  
map---{}  
map---{}

---

<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:** [October 1, 2020, 10:36am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/2 "2020-10-01T10:36:33Z")

</div>

What values do you have in `arr`?  
What does a document looks like? (In JSON format).

---

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 1, 2020, 10:50am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/3 "2020-10-01T10:50:57Z")

</div>

@dadoonet thanks for follow up . document is look like below :-

```auto
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 7875,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "contentsearch",
        "_type": "_doc",
        "_id": "kh4X33QBJG7M6evjj85r",
        "_score": 1,
        "_source": {
          "sub_content_download_count": null,
          "content_id": "104897",
          "soft_del": "0",
          "sub_content_property_3": "30.168000",
          "entity_id": "601506",
          "mount_point": null,
          "expiry_date": null,
          "task_id": "104899",
          "content_property_7": null,
          "content_property_27": null,
          "content_property_12": null,
          "content_property_17": null,
          "sub_content_property_9": null,
          "sub_content_property_21": null,
          "content_property_8": null,
          "sub_content_property_24": null,
          "content_property_37": null,
          "sub_content_property_29": null,
          "content_suspend": "F",
          "content_property_9": null,
          "content_property_48": "",
          "content_property_15": null,
          "content_property_13": null,
          "content_property_2": "Joko Joker",
          "content_property_36": null,
          "content_property_44": "",
          "order": 10000,
          "sub_content_id": "457419",
          "sub_content_property_30": null,
          "sub_content_property_28": null,
          "sub_content_property_1": "mp3",
          "content_property_19": null,
          "user_rating": null,
          "content_property_32": null,
          "content_property_30": null,
          "content_property_35": null,
          "content_property_42": "",
          "sub_content_property_15": null,
          "preview_image": "/opt/content_migration/Indosat.PNG",
          "content_property_21": null,
          "stage_id": "16",
          "sub_content_property_2": null,
          "content_property_11": null,
          "interface_id": null,
          "sub_content_property_17": null,
          "content_properties": null,
          "sub_content_property_11": null,
          "id": 457355,
          "tags": [
            "_contentsearch"
          ],
          "sub_content_property_25": null,
          "content_property_34": null,
          "sub_content_property_10": null,
          "content_download_count": null,
          "sub_content_property_12": null,
          "content_property_31": "PT. Virgo Ramayana",
          "sub_content_property_16": null,
          "content_property_46": "",
          "content_property_38": null,
          "content_property_29": "Bahasa",
          "sub_content_property_14": null,
          "sub_content_property_23": null,
          "upload_date": null,
          "content_property_25": null,
          "content_property_33": null,
          "sub_content_property_8": null,
          "location": "/cnt_repo02/rl/601/506/0/0000/0000/054.mp3",
          "content_property_26": "3",
          "sub_content_property_20": null,
          "sub_content_property_5": null,
          "content_property_18": null,
          "content_property_6": null,
          "content_property_22": null,
          "content_property_28": null,
          "last_change_date": null,
          "service_name": "popbarat_163_20191011",
          "content_property_4": null,
          "content_property_41": "",
          "content_property_40": null,
          "content_property_43": "",
          "category_search": "0",
          "sub_content_property_19": null,
          "content_category_map_id": "104899",
          "published_date": "2010-07-12T17:00:00.000Z",
          "is_preview": false,
          "description": "Transcoding",
          "content_owner": "601506",
          "sub_content_property_18": null,
          "access_count": "0",
          "status": "0",
          "category_id": "163",
          "sub_content_property_4": null,
          "content_property_24": null,
          "category_name": "popbarat",
          "sub_content_property_6": null,
          "content_property_45": "",
          "content_property_10": "Perkutrut Kentrut",
          "@version": "1",
          "sub_content_property_7": null,
          "sub_content_property_13": null,
          "content_property_5": "0630722",
          "service_id": "148",
          "content_property_47": "",
          "content_property_39": null,
          "sub_content_property_26": null,
          "content_property_23": "2900",
          "sub_content_properties": null,
          "timestamp": null,
          "content_property_3": null,
          "@timestamp": "2020-09-30T12:58:12.628Z",
          "content_property_49": "",
          "content_property_14": null,
          "content_property_1": null,
          "content_property_16": null,
          "content_property_20": null,
          "sub_content_property_27": null,
          "sub_content_property_22": null,
          "content_name": "Perkutrut Kentrut",
          "content_property_50": ""
        }
      }
    ]
  }
}

```

And arr containing new String{"stage\_id","sub\_content\_property\_1"}

exclude array will be null only.

---

<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:** [October 1, 2020, 1:27pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/4 "2020-10-01T13:27:29Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

---

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 1, 2020, 1:52pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/5 "2020-10-01T13:52:49Z")

</div>

@dadoonet done.

---

<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:** [October 1, 2020, 2:25pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/6 "2020-10-01T14:25:21Z")

</div>

It's note. Please check again and don't forget to save your modifications. Once updated, you should see:

```auto
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },

```

instead of

{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"skipped": 0,  
"failed": 0  
},

---

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 5, 2020, 4:57am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/7 "2020-10-05T04:57:42Z")

</div>

ok @dadoonet

---

<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:** [October 7, 2020, 4:25pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/8 "2020-10-07T16:25:19Z")

</div>

Could you also update this [Unable to get Source filter while doing elastic search with spring boot class org.elasticsearch.search.builder.SearchSourceBuilder](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/3)

---

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 8, 2020, 4:06am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/9 "2020-10-08T04:06:09Z")

</div>

[quote="Rajan\_Gupta, post:3, topic:250640"]  
{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": {  
"value": 7875,  
"relation": "eq"  
},  
"max\_score": 1,  
"hits": [  
{  
"\_index": "contentsearch",  
"\_type": "\_doc",  
"\_id": "kh4X33QBJG7M6evjj85r",  
"\_score": 1,  
"\_source": {  
"sub\_content\_download\_count": null,  
"content\_id": "104897",  
"soft\_del": "0",  
"sub\_content\_property\_3": "30.168000",  
"entity\_id": "601506",  
"mount\_point": null,  
"expiry\_date": null,  
"task\_id": "104899",  
"content\_property\_7": null,  
"content\_property\_27": null,  
"content\_property\_12": null,  
"content\_property\_17": null,  
"sub\_content\_property\_9": null,  
"sub\_content\_property\_21": null,  
"content\_property\_8": null,  
"sub\_content\_property\_24": null,  
"content\_property\_37": null,  
"sub\_content\_property\_29": null,  
"content\_suspend": "F",  
"content\_property\_9": null,  
"content\_property\_48": "",  
"content\_property\_15": null,  
"content\_property\_13": null,  
"content\_property\_2": "Joko Joker",  
"content\_property\_36": null,  
"content\_property\_44": "",  
"order": 10000,  
"sub\_content\_id": "457419",  
"sub\_content\_property\_30": null,  
"sub\_content\_property\_28": null,  
"sub\_content\_property\_1": "mp3",  
"content\_property\_19": null,  
"user\_rating": null,  
"content\_property\_32": null,  
"content\_property\_30": null,  
"content\_property\_35": null,  
"content\_property\_42": "",  
"sub\_content\_property\_15": null,  
"preview\_image": "/opt/content\_migration/Indosat.PNG",  
"content\_property\_21": null,  
"stage\_id": "16",  
"sub\_content\_property\_2": null,  
"content\_property\_11": null,  
"interface\_id": null,  
"sub\_content\_property\_17": null,  
"content\_properties": null,  
"sub\_content\_property\_11": null,  
"id": 457355,  
"tags": [  
"\_contentsearch"  
],  
"sub\_content\_property\_25": null,  
"content\_property\_34": null,  
"sub\_content\_property\_10": null,  
"content\_download\_count": null,  
"sub\_content\_property\_12": null,  
"content\_property\_31": "PT. Virgo Ramayana",  
"sub\_content\_property\_16": null,  
"content\_property\_46": "",  
"content\_property\_38": null,  
"content\_property\_29": "Bahasa",  
"sub\_content\_property\_14": null,  
"sub\_content\_property\_23": null,  
"upload\_date": null,  
"content\_property\_25": null,  
"content\_property\_33": null,  
"sub\_content\_property\_8": null,  
"location": "/cnt\_repo02/rl/601/506/0/0000/0000/054.mp3",  
"content\_property\_26": "3",  
"sub\_content\_property\_20": null,  
"sub\_content\_property\_5": null,  
"content\_property\_18": null,  
"content\_property\_6": null,  
"content\_property\_22": null,  
"content\_property\_28": null,  
"last\_change\_date": null,  
"service\_name": "popbarat\_163\_20191011",  
"content\_property\_4": null,  
"content\_property\_41": "",  
"content\_property\_40": null,  
"content\_property\_43": "",  
"category\_search": "0",  
"sub\_content\_property\_19": null,  
"content\_category\_map\_id": "104899",  
"published\_date": "2010-07-12T17:00:00.000Z",  
"is\_preview": false,  
"description": "Transcoding",  
"content\_owner": "601506",  
"sub\_content\_property\_18": null,  
"access\_count": "0",  
"status": "0",  
"category\_id": "163",  
"sub\_content\_property\_4": null,  
"content\_property\_24": null,  
"category\_name": "popbarat",  
"sub\_content\_property\_6": null,  
"content\_property\_45": "",  
"content\_property\_10": "Perkutrut Kentrut",  
"@version": "1",  
"sub\_content\_property\_7": null,  
"sub\_content\_property\_13": null,  
"content\_property\_5": "0630722",  
"service\_id": "148",  
"content\_property\_47": "",  
"content\_property\_39": null,  
"sub\_content\_property\_26": null,  
"content\_property\_23": "2900",  
"sub\_content\_properties": null,  
"timestamp": null,  
"content\_property\_3": null,  
"@timestamp": "2020-09-30T12:58:12.628Z",  
"content\_property\_49": "",  
"content\_property\_14": null,  
"content\_property\_1": null,  
"content\_property\_16": null,  
"content\_property\_20": null,  
"sub\_content\_property\_27": null,  
"sub\_content\_property\_22": null,  
"content\_name": "Perkutrut Kentrut",  
"content\_property\_50": ""  
}  
}  
]  
}  
}

---

<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:** [October 8, 2020, 6:13am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/10 "2020-10-08T06:13:28Z")

</div>

Is there anything you are not able to do or understand where I could help?

---

<div class="post-metadata">

**Author:** ![Rajan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajan_gupta/32/76203_2.png) [@Rajan\_Gupta](https://discuss.elastic.co/u/Rajan_Gupta)\
**Post date:** [October 8, 2020, 6:16am UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/11 "2020-10-08T06:16:23Z")

</div>

I m not able to get it what should i have to do here. I used preformatted text for this. But still you are telling i m wrong. So if you could help in that case it wil be greatful.

---

<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:** [October 12, 2020, 4:26pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/13 "2020-10-12T16:26:03Z")

</div>

I edited your post. Just edit it again to see what I put to make it readable.

Could you try to change this line:

```
searchSourceBuilder.fetchSource(true).fetchSource((String[]) outParamList.toArray(arr),null);

```

to

```
searchSourceBuilder.fetchSource((String[]) outParamList.toArray(arr), null);
```

---

<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:** [November 9, 2020, 4:26pm UTC](https://discuss.elastic.co/t/unable-to-get-source-filter-while-doing-elastic-search-with-spring-boot-class-org-elasticsearch-search-builder-searchsourcebuilder/250640/14 "2020-11-09T16:26:16Z")

</div>

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