# Filter condition to check if 2 docs lie in each other's distance range

**URL:** <https://discuss.elastic.co/t/filter-condition-to-check-if-2-docs-lie-in-each-others-distance-range/148654>\
**Category:** Elasticsearch\
**Created:** [September 14, 2018, 4:35pm UTC](https://discuss.elastic.co/t/filter-condition-to-check-if-2-docs-lie-in-each-others-distance-range/148654 "2018-09-14T16:35:30Z")\
**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:** [September 17, 2018, 6:44pm UTC](https://discuss.elastic.co/t/filter-condition-to-check-if-2-docs-lie-in-each-others-distance-range/148654/6 "2018-09-17T18:44:09Z")

</div>

Performance would depend on how many candidate docs were in range of Doc X. It wouldn't scale well for lots of candidates, that's for sure.

I think this is similar to a [question I also failed to answer](https://discuss.elastic.co/t/how-to-get-only-n-documents-for-each-value/49795/6?u=loren) a while back, which also seemed like a computational geometry problem that could not be solved with a single ES query. Sorry I could not be more helpful!

---

_[View the full topic](https://discuss.elastic.co/t/filter-condition-to-check-if-2-docs-lie-in-each-others-distance-range/148654)._
