Search is not giving expected results

I am trying to connect to elasticsearch and do some basic query. The code am trying is :

RestHighLevelClient client = new RestHighLevelClient(
				RestClient.builder(new HttpHost("localhost", 30100, "http")));
				
SearchRequest sr = new SearchRequest(INDEX);
sr.indicesOptions(IndicesOptions.lenientExpandOpen());

SearchSourceBuilder ssb = new SearchSourceBuilder();
sr.source(ssb);
 AggregationBuilder aggregation =
		    AggregationBuilders
		        .filters("agg",
		            new FiltersAggregator.KeyedFilter("level", QueryBuilders.termQuery("logLevel", "ERROR")));
	
	ssb.aggregation(aggregation);
SearchResponse response = null;

try {
	response = client.search(sr);
	System.out.println("total hits ::: " + response.getHits().getTotalHits());

} catch (IOException e) {
e.printStackTrace();
} finally {
try {
	client.close();
} catch (IOException e) {
	e.printStackTrace();
}
}

System.out.println(response);

I also want to give a date range but am not sure how I can do that. kindly help.

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