# Query help - return proximity between terms?

**URL:** <https://discuss.elastic.co/t/query-help-return-proximity-between-terms/306604>\
**Category:** Elasticsearch\
**Created:** [June 7, 2022, 8:57pm UTC](https://discuss.elastic.co/t/query-help-return-proximity-between-terms/306604 "2022-06-07T20:57:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iross](https://avatars.discourse-cdn.com/v4/letter/i/c77e96/32.png) [@iross](https://discuss.elastic.co/u/iross)\
**Post date:** [June 7, 2022, 8:57pm UTC](https://discuss.elastic.co/t/query-help-return-proximity-between-terms/306604/1 "2022-06-07T20:57:14Z")

</div>

Hello-  
I'm interested in returning the minimum "distance" between two terms within an (analyzed) text document. For example, given a sentence of "The quick brown fox jumped over the lazy dog," I'd like to be able to extract (ignoring stop words for simplicity):

```auto
min_distance("brown", "fox") => 1
min_distance("brown", "dog") => 6

```

From what I've been able to find, the most straightforward way to do this would be to store the term\_vector positions, find the positions for the terms I'm interested in, and then compute the smallest positional distance between them.

Is there a more clever, direct way to go about it? Is there some way to use a wide-open span query but have the response include the computed slop between the terms, for example?

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, 2022, 8:58pm UTC](https://discuss.elastic.co/t/query-help-return-proximity-between-terms/306604/2 "2022-07-05T20:58:10Z")

</div>

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