# getTotalHits isn't the same on the same search

**URL:** https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894
**Category:** Elasticsearch
**Created:** [July 23, 2013, 10:19am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894 "2013-07-23T10:19:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Gaydenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_gaydenko/32/914_2.png) [@Andrew\_Gaydenko](https://discuss.elastic.co/u/Andrew_Gaydenko)
#### Post date: [July 23, 2013, 10:19am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/1 "2013-07-23T10:19:38Z")

</div>

On few sequential search requests getTotalHits returns different values.  
Why?  
Of course, there wasn't any indexing between requests.More over, there  
wasn't any indexing since ES start 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 23, 2013, 10:31am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/2 "2013-07-23T10:31:44Z")

</div>

I've seen that in the past on a cluster with 2 nodes having shards with not the same number of docs due to a split brain issue.  
Do you have one node or many?

Check number of docs per shard and look if there is a difference between primary and replicas.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 23 juil. 2013 à 12:19, Andrew Gaydenko [andrew.gaydenko@gmail.com](mailto:andrew.gaydenko@gmail.com) a écrit :

> On few sequential search requests getTotalHits returns different values. Why?  
> Of course, there wasn't any indexing between requests.More over, there wasn't any indexing since ES start 🙂
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Andrew\_Gaydenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_gaydenko/32/914_2.png) [@Andrew\_Gaydenko](https://discuss.elastic.co/u/Andrew_Gaydenko)
#### Post date: [July 23, 2013, 10:44am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/3 "2013-07-23T10:44:17Z")

</div>

On Tuesday, July 23, 2013 2:31:44 PM UTC+4, David Pilato wrote:

> I've seen that in the past on a cluster with 2 nodes having shards with  
> not the same number of docs due to a split brain issue.  
> Do you have one node or many?
> 
> Check number of docs per shard and look if there is a difference between  
> primary and replicas.

I play with the only node with

index.number\_of\_shards: 1  
index.number\_of\_replicas: 0

in config.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 23, 2013, 10:52am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/4 "2013-07-23T10:52:59Z")

</div>

That should not happen with the same exact query with no indexing / refreshing in the mean time.

What does your query look like?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 23 juil. 2013 à 12:44, Andrew Gaydenko [andrew.gaydenko@gmail.com](mailto:andrew.gaydenko@gmail.com) a écrit :

> On Tuesday, July 23, 2013 2:31:44 PM UTC+4, David Pilato wrote:  
> I've seen that in the past on a cluster with 2 nodes having shards with not the same number of docs due to a split brain issue.  
> Do you have one node or many?
> 
> Check number of docs per shard and look if there is a difference between primary and replicas.
> 
> I play with the only node with
> 
> index.number\_of\_shards: 1  
> index.number\_of\_replicas: 0
> 
> in config.
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Andrew\_Gaydenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_gaydenko/32/914_2.png) [@Andrew\_Gaydenko](https://discuss.elastic.co/u/Andrew_Gaydenko)
#### Post date: [July 23, 2013, 11:01am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/5 "2013-07-23T11:01:18Z")

</div>

On Tuesday, July 23, 2013 2:52:59 PM UTC+4, David Pilato wrote:

> That should not happen with the same exact query with no indexing /  
> refreshing in the mean time.

You are absolutely right! It is my fault - the reason is in my code.  
Please, forgive me.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:25am UTC](https://discuss.elastic.co/t/gettotalhits-isnt-the-same-on-the-same-search/12894/6 "2017-07-06T02:25:05Z")

</div>


