# Aggregation not hitting all shards (ElasticSearch 1.7.4)

**URL:** <https://discuss.elastic.co/t/aggregation-not-hitting-all-shards-elasticsearch-1-7-4/106574>\
**Category:** Elasticsearch\
**Created:** [November 6, 2017, 6:14pm UTC](https://discuss.elastic.co/t/aggregation-not-hitting-all-shards-elasticsearch-1-7-4/106574 "2017-11-06T18:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Singh1](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@Vishal\_Singh1](https://discuss.elastic.co/u/Vishal_Singh1)\
**Post date:** [November 6, 2017, 6:14pm UTC](https://discuss.elastic.co/t/aggregation-not-hitting-all-shards-elasticsearch-1-7-4/106574/1 "2017-11-06T18:14:53Z")

</div>

q={"aggs"=\>{"ids"=\>{"terms"=\>{"field"=\>"id", "size"=\>10000}}}}

I am using ES 1.7.4  
a\_count = JSON.parse(`curl -s 'http://localhost:9200}/index/_search' -d '#{q.to_json}'`)['aggregations']['ids']['buckets'].count

s\_count = JSON.parse(`curl -s 'http://localhost:9200}/index/_search?q=_exists_:id'`)["hits"]

^^ Both are returning different result. s\_count is correct and a\_count is lower than s\_count. Aggregation is returning all buckets but ids are empty.

After doing some research, I found that aggregation is skipping some shards.

But If I reindex or migrate the index to different cluster then count is same for search and aggregation.

I have no idea what may be causing this. Any help would be appreciated.

EDIT: I did this query in row

a\_count = JSON.parse(curl -s '[http://localhost:9200](http://localhost:9200)}/index/\_search' -d '#{q.to\_json}')['aggregations']['ids']['buckets'].count  
--\> 4  
a\_count = JSON.parse(curl -s '[http://localhost:9200](http://localhost:9200)}/index/\_search' -d '#{q.to\_json}')['aggregations']['ids']['buckets'].count  
--\> 3  
a\_count = JSON.parse(curl -s '[http://localhost:9200](http://localhost:9200)}/index/\_search' -d '#{q.to\_json}')['aggregations']['ids']['buckets'].count  
--\> 4  
a\_count = JSON.parse(curl -s '[http://localhost:9200](http://localhost:9200)}/index/\_search' -d '#{q.to\_json}')['aggregations']['ids']['buckets'].count  
-\> 3

How same query is returning two results when executed again and again?

did some more research

irb(main):184:0\* a\_count = JSON.parse(`curl -s 'http://localhost:9200}/index/_search?routing=5' -d '#{q.to_json}'`)['aggregations']['ids']['buckets']  
=\> [{"key"=\>3435973840252, "doc\_count"=\>1}]  
irb(main):185:0\> a\_count = JSON.parse(`curl -s 'http://localhost:9200}/index/_search?routing=5' -d '#{q.to_json}'`)['aggregations']['ids']['buckets']  
=\> []

---

<div class="post-metadata">

**Author:** ![Vishal\_Singh1](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@Vishal\_Singh1](https://discuss.elastic.co/u/Vishal_Singh1)\
**Post date:** [November 7, 2017, 1:19pm UTC](https://discuss.elastic.co/t/aggregation-not-hitting-all-shards-elasticsearch-1-7-4/106574/2 "2017-11-07T13:19:43Z")

</div>

This is very urgent. I was wondering if anyone can give me any insight on how to proceed on this.

---

<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:** [December 5, 2017, 1:20pm UTC](https://discuss.elastic.co/t/aggregation-not-hitting-all-shards-elasticsearch-1-7-4/106574/3 "2017-12-05T13:20:12Z")

</div>

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