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()) {
llist.add(hit.getSourceAsMap());
}
In this we can take specific fields under SourceAsMap like "computer_name and type" like these two instead of showing all?
Any idea
dadoonet
(David Pilato)
March 20, 2019, 4:32pm
2
hit.getSourceAsMap().get("computer_name")
?
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
But can only one fields but i need more than one fields? when i more than one fields it throws error
dadoonet
(David Pilato)
March 20, 2019, 4:51pm
6
Share the code you wrote.
public @ResponseBody List datesearch2() throws IOException
{
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("winlogbeat-6.5.3-2019.03.18");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.rangeQuery("@timestamp").from("2019-03-18T07:00:04.874Z").to("2019-03-18T09:52:04.641Z"));
searchRequest.source(searchSourceBuilder);
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
List<Object> llist = new ArrayList<Object>();
for (SearchHit hit : response.getHits())
{
llist.add(hit.getSourceAsMap().get("computer_name"));
}
return llist;
}
I need more than one field like "computer_name" and "type"
dadoonet
(David Pilato)
March 20, 2019, 4:59pm
10
And? What is failing when you do that? What is the code you are using to do that?
llist.add(hit.getSourceAsMap().get("conputer_name","type"));
it shows error like this:
The method get(Object) in the type Map<String,Object> is not applicable for the arguments (String, String)
dadoonet
(David Pilato)
March 20, 2019, 5:02pm
12
Ok. That's a Java question. Do you know Java?
okay I will try and get it
dadoonet
(David Pilato)
March 20, 2019, 5:04pm
14
This:
llist.add(hit.getSourceAsMap().get("computer_name"));
llist.add(hit.getSourceAsMap().get("type"));
But I'm still unsure that fits your needs.
you are great!!!!!! it's working thank you
system
(system)
Closed
April 17, 2019, 5:10pm
17
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.