# How to get only n documents for each value

**URL:** <https://discuss.elastic.co/t/how-to-get-only-n-documents-for-each-value/49795>\
**Category:** Elasticsearch\
**Created:** [May 11, 2016, 3:36pm UTC](https://discuss.elastic.co/t/how-to-get-only-n-documents-for-each-value/49795 "2016-05-11T15:36:53Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [May 12, 2016, 10:42pm UTC](https://discuss.elastic.co/t/how-to-get-only-n-documents-for-each-value/49795/6 "2016-05-12T22:42:44Z")

</div>

Sorry, I'm not familiar with any single ES query that would solve a [proximity problem](https://en.wikipedia.org/wiki/Proximity_problems) like that. The brute force approach of iterating through your set of points and running that Geo Distance Range Query is probably the most straightforward, but you may be able to implement something faster using computational geometry, like in the [closest pair of points problem](https://en.wikipedia.org/wiki/Closest_pair_of_points_problem).

---

_[View the full topic](https://discuss.elastic.co/t/how-to-get-only-n-documents-for-each-value/49795)._
