Elasticsearch API SourceAsMap

I use this take only SourceAsMap

List<Object> llist = new ArrayList<Object>();
SearchResponse response = client.search(new SearchRequest("test"), RequestOptions.DEFAULT);
for (SearchHit hit : response.getHits()) {

In this we can take specific fields under SourceAsMap like "computer_name and type" like these two instead of showing all?
Any idea


I'm sorry but I think it's a Java question now and not related to elasticsearch anymore. Am I right?

At the end, what do you want to do?

I want only specific to show specific field instead of more fields

I will try and say wait

But can only one fields but i need more than one fields? when i more than one fields it throws error

Share the code you wrote.

public @ResponseBody List datesearch2() throws IOException

	 SearchRequest searchRequest = new SearchRequest();
	 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
	 SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
	 List<Object> llist = new ArrayList<Object>();
	 for (SearchHit hit : response.getHits()) 
	 return llist;

What is failing here?

I need more than one field like "computer_name" and "type"

And? What is failing when you do that? What is the code you are using to do that?


it shows error like this:
The method get(Object) in the type Map<String,Object> is not applicable for the arguments (String, String)

Ok. That's a Java question. Do you know Java?

okay I will try and get it



But I'm still unsure that fits your needs.

okay i will try

you are great!!!!!! it's working thank you

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