# Search returns fewers results than count

**URL:** <https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406>\
**Category:** Elasticsearch\
**Created:** [March 13, 2017, 7:35pm UTC](https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406 "2017-03-13T19:35:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakehschwartz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakehschwartz/32/9814_2.png) [@jakehschwartz](https://discuss.elastic.co/u/jakehschwartz)\
**Post date:** [March 13, 2017, 7:35pm UTC](https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406/1 "2017-03-13T19:35:03Z")

</div>

Using Elasticsearch 1.7.5

We were attempting to do a count query followed by a search query if a certain threshold was returned by the count but we saw the sometimes that could would say there are X documents, but when we did the search, the total was X-1.

Note: We saw the same behavior for search\_type=count and using size=0 to return no results. Did not use \_count API because I thought I read that it had different behavior.

Here are some logs:

**Count** :  
_request_:  
`POST /2017-03-11/_search?search_type=count { "filter": { "and": [{ "query": { "query_string": { "query": "..." } } }, { "range": { "created_at": { "gte": "2017-03-11T04:38:13Z", "lt": "2017-03-11T04:40:12Z" } } }] }, "sort": [{ "created_at": { "order": "desc" } }], "size": 25, "_source": ["field_names"] }`

_response_:  
{"took":58,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":69,"max\_score":0.0,"hits":[]}}

**Search** :  
_request_:  
`POST /2017-03-11/_search { "filter": { "and": [{ "query": { "query_string": { "query": "..." } } }, { "range": { "created_at": { "gte": "2017-03-11T04:38:13Z", "lt": "2017-03-11T04:40:12Z" } } }] }, "sort": [{ "created_at": { "order": "desc" } }], "size": 25, "_source": ["field_names"] }`

_response_:  
`{"took":35,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":68,"max_score":null,"hits":[...]}}`

Let me know if there would be any more useful information

Thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2017, 7:59pm UTC](https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406/2 "2017-03-13T19:59:11Z")

</div>

Hey,

can you try this with a [preference](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-preference.html) and see if it yields the same results?

Maybe (note: wild assumption here) data in your shards is diverting.

P.S. Upgrading might be a wise idea (but I guess you knew that already 🙂

--Alex

---

<div class="post-metadata">

**Author:** ![jakehschwartz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakehschwartz/32/9814_2.png) [@jakehschwartz](https://discuss.elastic.co/u/jakehschwartz)\
**Post date:** [March 13, 2017, 9:53pm UTC](https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406/3 "2017-03-13T21:53:32Z")

</div>

Upgrading is unfortunately off the table for right now, but I'll try using a preference. This doesn't happen every time so I'll keep it running and see if it happens in the next 24 hours. Thanks.

---

<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:** [April 10, 2017, 9:53pm UTC](https://discuss.elastic.co/t/search-returns-fewers-results-than-count/78406/4 "2017-04-10T21:53:33Z")

</div>

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