# Search is not giving expected results

**URL:** <https://discuss.elastic.co/t/search-is-not-giving-expected-results/146108>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 6:09am UTC](https://discuss.elastic.co/t/search-is-not-giving-expected-results/146108 "2018-08-27T06:09:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raghuveer\_SJ](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@Raghuveer\_SJ](https://discuss.elastic.co/u/Raghuveer_SJ)\
**Post date:** [August 27, 2018, 6:09am UTC](https://discuss.elastic.co/t/search-is-not-giving-expected-results/146108/1 "2018-08-27T06:09:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 24, 2018, 6:10am UTC](https://discuss.elastic.co/t/search-is-not-giving-expected-results/146108/2 "2018-09-24T06:10:05Z")

</div>

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