Scroll Search Multiple Fields

Hi, I want to do a Scroll search only for some fields, I have 5 fields like this: name, content, type_message, status and date and I want to get only 2 fields with a search scroll. I have this:

SearchResponse scroll_traffic = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.SCAN)
.setScroll(new TimeValue(6000))
.setQuery(QueryBuilders.matchAllQuery())
.setSize(20)
.execute().actionGet();

But I want to add fields to filter my search, How can I do that with scroll?

Thanks.

client.prepareSearch(...).setTypes(...)
				.setQuery(...)
				.setSearchType(searchType)
				.addFields("field1", "field2", "field3", "etc..."
						)
						.setScroll(new TimeValue(...))
						.setSize(...)
						.execute().actionGet();

Also when you read ScrollResponse, you will not get back hits but rather fields...

for (SearchHit hit : scrollResp.getHits().getHits()) {
    String line = new String();
    			       
    // Quick dirty way to format as CSV.    			    	
 	for(Entry<String, SearchHitField> e : hit.fields().entrySet()){
    		line += "\"" + e.getValue().value().toString() + "\",";
    }
    line += "\r\n";
}
1 Like

Trank you so much