# Different results with/without preference=\_primary\_first/\_replica\_first using count API

**URL:** <https://discuss.elastic.co/t/different-results-with-without-preference--primary-first--replica-first-using-count-api/21704>\
**Category:** Elasticsearch\
**Created:** [January 19, 2015, 5:04am UTC](https://discuss.elastic.co/t/different-results-with-without-preference--primary-first--replica-first-using-count-api/21704 "2015-01-19T05:04:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiaoting\_Ye](https://avatars.discourse-cdn.com/v4/letter/x/eb9ed0/32.png) [@Xiaoting\_Ye](https://discuss.elastic.co/u/Xiaoting_Ye)\
**Post date:** [January 19, 2015, 5:04am UTC](https://discuss.elastic.co/t/different-results-with-without-preference--primary-first--replica-first-using-count-api/21704/1 "2015-01-19T05:04:05Z")

</div>

Hi,

I'm bulk indexing massive data however when I check the status, I found  
some interesting results:

When I called: curl -XGET  
'[http://localhost:9200/my\_index/my\_type/\_count?pretty](http://localhost:9200/my_index/my_type/_count?pretty)' -d '{"query" : {  
"filtered": {"filter" : {"exists" : {"field": "visibility"}}}}}}'

It returned:  
{  
"count" : 27395968,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
}  
}

When I called: curl -XGET  
'[http://localhost:9200/my\_index/my\_type/\_count?pretty&preference=](http://localhost:9200/my_index/my_type/_count?pretty&preference=)  
_\_primary\_first_' -d '{"query" : { "filtered": {"filter" : {"exists" :  
{"field": "visibility"}}}}}}'

It returned as below.  
{  
"count" : 36802421,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
}  
}

As we can see, there is a hugh difference between the the above two  
results. So I thought it was caused by the inconsistency between the  
primary shard and the replicas.

Then I called curl -XGET  
'[http://localhost:9200/my\_index/my\_type/\_count?pretty&preference=](http://localhost:9200/my_index/my_type/_count?pretty&preference=)  
_\_replica\_first_' -d '{"query" : { "filtered": {"filter" : {"exists" :  
{"field": "visibility"}}}}}}'

To my surprise, the count is roughly the same(slight difference caused by  
bulk indexing that I'm still running).

{  
"count" : 36867417,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
}  
}

So any idea why this happen?

Thanks!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/df5ac31e-ad17-4b8c-b979-18c4a977bb0c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df5ac31e-ad17-4b8c-b979-18c4a977bb0c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:38am UTC](https://discuss.elastic.co/t/different-results-with-without-preference--primary-first--replica-first-using-count-api/21704/2 "2017-07-06T00:38:08Z")

</div>


