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

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

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---{}

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

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

{
  "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.

Please format your code, logs or configuration files using </> icon as explained in this guide 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:

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.

@dadoonet done.

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

{
  "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
},

ok @dadoonet

Could you also update this Unable to get Source filter while doing elastic search with spring boot class org.elasticsearch.search.builder.SearchSourceBuilder

[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": ""
}
}
]
}
}

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

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.

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);

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