# Query needed for ensuring position of word

**URL:** <https://discuss.elastic.co/t/query-needed-for-ensuring-position-of-word/168229>\
**Category:** Elasticsearch\
**Created:** [February 13, 2019, 1:15pm UTC](https://discuss.elastic.co/t/query-needed-for-ensuring-position-of-word/168229 "2019-02-13T13:15:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pokaleshrey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pokaleshrey/32/48680_2.png) [@pokaleshrey](https://discuss.elastic.co/u/pokaleshrey)\
**Post date:** [February 13, 2019, 1:15pm UTC](https://discuss.elastic.co/t/query-needed-for-ensuring-position-of-word/168229/1 "2019-02-13T13:15:36Z")

</div>

Is there a way to form the query which will ensure the position of the word while matching ?

Example:  
Indexed phrase is "Dark of the moon" (Standard analyzed, no stopword filter)  
I should have a query where in i should be able to match below:  
"Dark x y z"  
"Dark x y moon"  
"x y z moon"

Summing it up: I should be able to check position of the word given any input.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 15, 2019, 9:59pm UTC](https://discuss.elastic.co/t/query-needed-for-ensuring-position-of-word/168229/2 "2019-02-15T21:59:53Z")

</div>

Available from v 7.0 [Interval queries](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-intervals-query.html) will allow fine-grained control over the order and proximity of matching terms.  
In the versions 6.x, you can take advantage of Span queries. For example, [Span First Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html) matches at the beginning of the field.

---

<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:** [March 15, 2019, 9:59pm UTC](https://discuss.elastic.co/t/query-needed-for-ensuring-position-of-word/168229/3 "2019-03-15T21:59:57Z")

</div>

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