# Total Hits in elastic Search prepareSearch() behaves in an inconsistent manner

**URL:** https://discuss.elastic.co/t/total-hits-in-elastic-search-preparesearch-behaves-in-an-inconsistent-manner/150963
**Category:** Elasticsearch
**Created:** [October 4, 2018, 4:39am UTC](https://discuss.elastic.co/t/total-hits-in-elastic-search-preparesearch-behaves-in-an-inconsistent-manner/150963 "2018-10-04T04:39:49Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![RAM\_NATHAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_nathan/32/50393_2.png) [@RAM\_NATHAN](https://discuss.elastic.co/u/RAM_NATHAN)
#### Post date: [October 15, 2018, 11:21am UTC](https://discuss.elastic.co/t/total-hits-in-elastic-search-preparesearch-behaves-in-an-inconsistent-manner/150963/15 "2018-10-15T11:21:15Z")

</div>

> [@johnrabi](#):
>
> QueryBuilder queryBuilder = QueryBuilders.matchPhraseQuery("\_all", "Test Type Search");

MatchPhrase too cant help. Again inconsistent results some times 28, sometimes 10.  
please find the response below.

{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 22,  
"max\_score": 0.021978907,  
"hits": [..........]  
}  
}

I'm using reactive pattern. Does it make any difference?

Observable.create(new OnSubscribe\<List\<InnerSearchHits\>\>() {   
@Override  
public void call(Subscriber\<? super List\<InnerSearchHits\>\> t) {

```
			QueryBuilder queryBuilder = QueryBuilders.matchPhraseQuery(filterKey,filterValue);
			ListenableActionFuture<SearchResponse> f = esClient.getESClient().prepareSearch(index)
            .setQuery(queryBuilder).
            setFrom(0)
            .setSize(10000)
            .execute();
			Observable.from(f).map(x -> {
				List<InnerSearchHits<E>> innerSearchHits = new ArrayList<InnerSearchHits<E>>();
    			SearchHits hits = x.getHits();
    		
    			for (SearchHit searchHit : hits) {
    		.............
				}
                return innerSearchHits;
			}).onErrorReturn(e -> {      			
				......
        		return null;
			}).subscribe(...
				}
			}, e -> { 
				if (!t.isUnsubscribed()) {
					t.onError(e);
				}
			}, () -> {
				if (!t.isUnsubscribed()) {
					t.onCompleted();
				}
			});
			
		}
	});

```

Same code is working fine, if I do remote debugging

---

_[View the full topic](https://discuss.elastic.co/t/total-hits-in-elastic-search-preparesearch-behaves-in-an-inconsistent-manner/150963)._
