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 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!