Can I specify my SearchSourceBuilder or SearchRequest for return in SearchResponse only fields without metadata? Include fields and Exclude don't work. I want to return only code.keyword and id.keyword fields in response. This is my SearchRequest:
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
.size(size)
.from(from);
String[] includeFields = new String[]{"code.keyword", "id.keyword"};
String[] excludeFields = new String[]{"index", "id", "type", "score", "totalHits"};
sourceBuilder.docValueField("code.keyword");
sourceBuilder.docValueField("id.keyword");
sourceBuilder.fetchSource(false);
QueryBuilder query = QueryBuilders.matchAllQuery();
SearchRequest request = new SearchRequest("indexName");
sourceBuilder.query(query);
sourceBuilder.timeout(TimeValue.timeValueMinutes(5));
request.source(sourceBuilder);
And it's my SearchResponse:
{
"took": 40,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": 1,
"hits": [
{
"_index": "core_event_usvc_provided",
"_type": "_doc",
"_id": "11a39e86-2b86-430e-9042-d59d58fb16d6",
"_score": 1,
"fields": {
"id.keyword": [
"11a39e86-2b86-430e-9042-d59d58fb16d6"
],
"code.keyword": [
"1.1.2-1"
]
}
},
{
"_index": "core_event_usvc_provided",
"_type": "_doc",
"_id": "7623a866-3f2e-4373-9b56-f819bac8717f",
"_score": 1,
"fields": {
"id.keyword": [
"7623a866-3f2e-4373-9b56-f819bac8717f"
],
"code.keyword": [
"3.02.02"
]
}
},
{
"_index": "core_event_usvc_provided",
"_type": "_doc",
"_id": "af6ebc01-8bf8-4e4f-978c-55a6a5ee898b",
"_score": 1,
"fields": {
"id.keyword": [
"af6ebc01-8bf8-4e4f-978c-55a6a5ee898b"
],
"code.keyword": [
"3.29.01"
]
}
},
{
"_index": "core_event_usvc_provided",
"_type": "_doc",
"_id": "26887750-23c0-4309-8985-e31aecf9460c",
"_score": 1,
"fields": {
"id.keyword": [
"26887750-23c0-4309-8985-e31aecf9460c"
],
"code.keyword": [
"156.25.15"
]
}
},
{
"_index": "core_event_usvc_provided",
"_type": "_doc",
"_id": "8bdbf877-3f08-439f-ad5a-02a3b1f337ef",
"_score": 1,
"fields": {
"id.keyword": [
"8bdbf877-3f08-439f-ad5a-02a3b1f337ef"
],
"code.keyword": [
"200.14.1.1"
]
}
}
]
}
}