# Query hits total greater than number of results returned

**URL:** https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371
**Category:** Elasticsearch
**Created:** [January 16, 2013, 11:37am UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371 "2013-01-16T11:37:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![random35743373](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@random35743373](https://discuss.elastic.co/u/random35743373)
#### Post date: [January 16, 2013, 11:37am UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/1 "2013-01-16T11:37:06Z")

</div>

I'm indexing 100 documents, then (after 2 seconds) I'm running a query that  
based on the data in a particular field. The result.hits.total says 100 but  
often there are only ~70 results returned. I've tried expicitly refreshing  
the index after adding the docs but it doesn't seem to make any difference.

If I wait a minute or two I do get the output I'm expecting and I  
understand there can be an indexing delay however saying there are 100  
results but only returning 70 seems like a bug to me.

--

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 16, 2013, 11:44am UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/2 "2013-01-16T11:44:52Z")

</div>

Are you setting your ID for your documents? Is it possible that sometimes you  
update an existing document instead of creating it?  
Do you use Bulk indexing? If so, did you check bulkResponses ?

Do you have always the same amount of documents when you search for it?  
What query do you run? Did you try a matchAll() to see if all docs are here?

David

Le 16 janvier 2013 à 12:37, [random35743373@googlemail.com](mailto:random35743373@googlemail.com) a écrit :

> I'm indexing 100 documents, then (after 2 seconds) I'm running a query that  
> based on the data in a particular field. The result.hits.total says 100 but  
> often there are only ~70 results returned. I've tried expicitly refreshing the  
> index after adding the docs but it doesn't seem to make any difference.
> 
> If I wait a minute or two I do get the output I'm expecting and I understand  
> there can be an indexing delay however saying there are 100 results but only  
> returning 70 seems like a bug to me.
> 
> --

--

---

<div class="post-metadata">

### Author: ![random35743373](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@random35743373](https://discuss.elastic.co/u/random35743373)
#### Post date: [January 16, 2013, 12:01pm UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/3 "2013-01-16T12:01:41Z")

</div>

I've just realised the title may be erroneous, I meant querying in the  
generic sense, I'm actually running a search (see exact call below).

I'm setting an ID for each doc. Before I index the docs I delete the index  
so I'm starting with a clean slate. I'm not using bulk anything. Every time  
I query the hits total says 100 (which is correct).

Here is my search  
[http://127.0.01:9200/my\_index/my\_doc/\_search](http://127.0.01:9200/my_index/my_doc/_search)  
{  
"fields": [  
"my\_field"  
],  
"size": 200,  
"from": 0,  
"query": {  
"term": {  
"my\_field": "my\_val"  
}  
}  
}

On Wednesday, January 16, 2013 11:44:52 AM UTC, David Pilato wrote:

> Are you setting your ID for your documents? Is it possible that  
> sometimes you update an existing document instead of creating it?  
> Do you use Bulk indexing? If so, did you check bulkResponses ?
> 
> Do you have always the same amount of documents when you search for it?  
> What query do you run? Did you try a matchAll() to see if all docs are  
> here?
> 
> David
> 
> Le 16 janvier 2013 à 12:37, [random3...@googlemail.com](mailto:random3...@googlemail.com) \<javascript:\> a  
> écrit :
> 
> I'm indexing 100 documents, then (after 2 seconds) I'm running a query  
> that based on the data in a particular field. The result.hits.total says  
> 100 but often there are only ~70 results returned. I've tried expicitly  
> refreshing the index after adding the docs but it doesn't seem to make any  
> difference.
> 
> If I wait a minute or two I do get the output I'm expecting and I  
> understand there can be an indexing delay however saying there are 100  
> results but only returning 70 seems like a bug to me.
> 
> --

--

---

<div class="post-metadata">

### Author: ![random35743373](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@random35743373](https://discuss.elastic.co/u/random35743373)
#### Post date: [January 16, 2013, 12:04pm UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/4 "2013-01-16T12:04:04Z")

</div>

I've just realised the title may be erroneous, I meant querying in the  
generic sense, I'm actually running a search (see exact call below).

I'm setting an ID for each doc. Before I index the docs I delete the index  
so I'm starting with a clean slate. I'm not using bulk anything. Every time  
I query the hits total says 100 (which is correct).

Here is my search  
[http://127.0.01:9200/my\_index/my\_doc/\_search](http://127.0.01:9200/my_index/my_doc/_search)  
#{

# "fields": [

# "my\_field"

# ],

# "size": 200,

# "from": 0,

# "query": {

# "term": {

# "my\_field": "my\_val"

# }

# }

#}

On Wednesday, January 16, 2013 11:44:52 AM UTC, David Pilato wrote:

> Are you setting your ID for your documents? Is it possible that  
> sometimes you update an existing document instead of creating it?  
> Do you use Bulk indexing? If so, did you check bulkResponses ?
> 
> Do you have always the same amount of documents when you search for it?  
> What query do you run? Did you try a matchAll() to see if all docs are  
> here?
> 
> David
> 
> Le 16 janvier 2013 à 12:37, [random3...@googlemail.com](mailto:random3...@googlemail.com) \<javascript:\> a  
> écrit :
> 
> I'm indexing 100 documents, then (after 2 seconds) I'm running a query  
> that based on the data in a particular field. The result.hits.total says  
> 100 but often there are only ~70 results returned. I've tried expicitly  
> refreshing the index after adding the docs but it doesn't seem to make any  
> difference.
> 
> If I wait a minute or two I do get the output I'm expecting and I  
> understand there can be an indexing delay however saying there are 100  
> results but only returning 70 seems like a bug to me.
> 
> --

--

---

<div class="post-metadata">

### Author: ![random35743373](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@random35743373](https://discuss.elastic.co/u/random35743373)
#### Post date: [January 16, 2013, 12:08pm UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/5 "2013-01-16T12:08:31Z")

</div>

Edit: I've posted this twice already and it keep being deleted, what am I  
doing wrong?

I've just realised the title may be erroneous, I meant querying in the  
generic sense, I'm actually running a search (see exact call below).

I'm setting an ID for each doc. Before I index the docs I delete the index  
so I'm starting with a clean slate. I'm not using bulk anything. Every time  
I query the hits total says 100 (which is correct).

Here is my search  
/my\_index/my\_doc/\_search  
\_ {  
\_ "fields": [  
\_ "my\_field"  
\_ ],  
\_ "size": 200,  
\_ "from": 0,  
\_ "query": {  
\_ "term": {  
\_ "my\_field": "my\_val"  
\_ }  
\_ }  
\_ }

On Wednesday, January 16, 2013 11:44:52 AM UTC, David Pilato wrote:

> Are you setting your ID for your documents? Is it possible that  
> sometimes you update an existing document instead of creating it?  
> Do you use Bulk indexing? If so, did you check bulkResponses ?
> 
> Do you have always the same amount of documents when you search for it?  
> What query do you run? Did you try a matchAll() to see if all docs are  
> here?
> 
> David
> 
> Le 16 janvier 2013 à 12:37, [random3...@googlemail.com](mailto:random3...@googlemail.com) \<javascript:\> a  
> écrit :
> 
> I'm indexing 100 documents, then (after 2 seconds) I'm running a query  
> that based on the data in a particular field. The result.hits.total says  
> 100 but often there are only ~70 results returned. I've tried expicitly  
> refreshing the index after adding the docs but it doesn't seem to make any  
> difference.
> 
> If I wait a minute or two I do get the output I'm expecting and I  
> understand there can be an indexing delay however saying there are 100  
> results but only returning 70 seems like a bug to me.
> 
> --

--

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 16, 2013, 12:18pm UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/6 "2013-01-16T12:18:59Z")

</div>

Are you able to build a curl recreation and gist it to help to reproduce your  
use case?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Le 16 janvier 2013 à 13:08, [random35743373@googlemail.com](mailto:random35743373@googlemail.com) a écrit :

> Edit: I've posted this twice already and it keep being deleted, what am I  
> doing wrong?
> 
> I've just realised the title may be erroneous, I meant querying in the  
> generic sense, I'm actually running a search (see exact call below).
> 
> I'm setting an ID for each doc. Before I index the docs I delete the index so  
> I'm starting with a clean slate. I'm not using bulk anything. Every time I  
> query the hits total says 100 (which is correct).
> 
> Here is my search  
> /my\_index/my\_doc/\_search  
> \_ {  
> \_ "fields": [  
> \_ "my\_field"  
> \_ ],  
> \_ "size": 200,  
> \_ "from": 0,  
> \_ "query": {  
> \_ "term": {  
> \_ "my\_field": "my\_val"  
> \_ }  
> \_ }  
> \_ }
> 
> On Wednesday, January 16, 2013 11:44:52 AM UTC, David Pilato wrote:
> 
> > > Are you setting your ID for your documents? Is it possible that  
> > > sometimes you update an existing document instead of creating it?  
> > > Do you use Bulk indexing? If so, did you check bulkResponses ?
> > 
> > Do you have always the same amount of documents when you search for it?  
> > What query do you run? Did you try a matchAll() to see if all docs are  
> > here?
> > 
> > David
> > 
> > Le 16 janvier 2013 à 12:37, [random3...@googlemail.com](mailto:random3...@googlemail.com) a écrit :
> > 
> > ```
> > > > > I'm indexing 100 documents, then (after 2 seconds) I'm running a
> > > > > query that based on the data in a particular field. The
> > > > > result.hits.total says 100 but often there are only ~70 results
> > > > > returned. I've tried expicitly refreshing the index after adding
> > > > > the docs but it doesn't seem to make any difference.
> > 
> > ```
> > 
> > > ```
> > > If I wait a minute or two I do get the output I'm expecting and I
> > > 
> > > ```
> > > 
> > > understand there can be an indexing delay however saying there are 100  
> > > results but only returning 70 seems like a bug to me.
> > > 
> > > ```
> > > --
> > > 
> > > ```
> > > 
> > > > >
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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: [July 6, 2017, 2:56am UTC](https://discuss.elastic.co/t/query-hits-total-greater-than-number-of-results-returned/10371/7 "2017-07-06T02:56:09Z")

</div>


