# Question regarding field collapsing and sharding

**URL:** <https://discuss.elastic.co/t/question-regarding-field-collapsing-and-sharding/43828>\
**Category:** Elasticsearch\
**Created:** [March 8, 2016, 8:13pm UTC](https://discuss.elastic.co/t/question-regarding-field-collapsing-and-sharding/43828 "2016-03-08T20:13:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsvachon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsvachon/32/20893_2.png) [@jsvachon](https://discuss.elastic.co/u/jsvachon)\
**Post date:** [March 8, 2016, 8:13pm UTC](https://discuss.elastic.co/t/question-regarding-field-collapsing-and-sharding/43828/1 "2016-03-08T20:13:18Z")

</div>

Hi all,

I am a total newbie with ES but got a very good experience with Solr and Lucene. I am currently playing with ES to see if it has the same issues/limitations as Solr mainly regarding field collapsing and sharding.

In Solr, if I want to group on a certain field (and get good numbers), I need to route documents with the same doc-value for a field to the same shard. (i.e all documents with value X for field F need to be on the same shard).

Is that true for ES as well? I tried following the example from the doc regarding the top\_hits aggregator and a sub aggregator like this:

[https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-metrics-top-hits-aggregation.html#\_field\_collapse\_example](https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-metrics-top-hits-aggregation.html#_field_collapse_example)

So far my request looks like this. (Basically get a list of employers sorted by the number of places/cities):

GET \_search  
{  
"size": 0,  
"query": {  
"match": {  
"description": "java"  
}  
},  
"aggs": {  
"top\_employers": {  
"terms": {  
"field": "employer\_id",  
"order": {  
"empl-place": "desc"  
},  
"size": 1  
},  
"aggs": {  
"top\_employer\_hits": {  
"top\_hits": {  
"\_source": [  
"place\_id",  
"content\_id"  
],"size":10  
}  
},  
"empl-place": {  
"value\_count": {  
"field": "place\_id"  
}  
}  
}  
}  
}  
}

and the result I am getting is ( I removed to stuff for clarity):

{  
...  
"aggregations": {  
"top\_employers": {  
...  
"buckets": [  
{  
...  
"top\_employer\_hits": {  
"hits": {  
"total": **4** ,  
"max\_score": 0.9461352,  
"hits": [  
{  
...  
"\_source": {  
"content\_id": "768474767",  
"place\_id": **485285**  
}  
},  
{  
...  
"\_source": {  
"content\_id": "768474767",  
"place\_id": **485285**  
}  
},  
{  
...  
"\_source": {  
"content\_id": "763490271",  
"place\_id": 0  
}  
},  
{  
....  
"\_source": {  
"content\_id": "768473591",  
"place\_id": **485285**  
}  
}  
]  
}  
}  
}  
]  
}  
}  
}

As you can see I am receiving multiple hits with the same value for the place\_id field. Could that be caused by the data not being distributed correctly?

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:** [July 5, 2017, 11:10pm UTC](https://discuss.elastic.co/t/question-regarding-field-collapsing-and-sharding/43828/2 "2017-07-05T23:10:08Z")

</div>


