# Bag of words query within a certain proximity

**URL:** <https://discuss.elastic.co/t/bag-of-words-query-within-a-certain-proximity/197920>\
**Category:** Elasticsearch\
**Created:** [September 3, 2019, 5:34pm UTC](https://discuss.elastic.co/t/bag-of-words-query-within-a-certain-proximity/197920 "2019-09-03T17:34:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philv](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@philv](https://discuss.elastic.co/u/philv)\
**Post date:** [September 3, 2019, 5:34pm UTC](https://discuss.elastic.co/t/bag-of-words-query-within-a-certain-proximity/197920/1 "2019-09-03T17:34:56Z")

</div>

I was wondering whether there's a way other than a span near query where I can specify a bag of words to be searched against a document but where the words can be in any order and have a defined slop? I was thinking of this in the context of a simplified search api, a bit like the query string query api, where I could write something like:

"one two three"~-2 where - represents 'any order'- ie., find these three words with a max of 2 intervening words, in any order in my document.

---

<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:** [October 1, 2019, 5:35pm UTC](https://discuss.elastic.co/t/bag-of-words-query-within-a-certain-proximity/197920/2 "2019-10-01T17:35:00Z")

</div>

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