# Search based on relative position

**URL:** <https://discuss.elastic.co/t/search-based-on-relative-position/13372>\
**Category:** Elasticsearch\
**Created:** [August 28, 2013, 4:29pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372 "2013-08-28T16:29:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ban\_Mido](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Ban\_Mido](https://discuss.elastic.co/u/Ban_Mido)\
**Post date:** [August 28, 2013, 4:29pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/1 "2013-08-28T16:29:09Z")

</div>

Hi ,

Is it possible to search giving the relative position of keywords.

Like , i want to search for "Indian health" . I want these terms to exactly  
come next to each other , any other order is considered as false result.  
Is this possible using elasticsearch ?

Thanks  
Vineeth

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 28, 2013, 4:35pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/2 "2013-08-28T16:35:31Z")

</div>

You can use any query that supports the slop parameter. The span queries  
will give you more control over the exact positioning. A slop of zero means  
exact phrase matching.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Cheers,

Ivan

On Wed, Aug 28, 2013 at 9:29 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:

> Hi ,
> 
> Is it possible to search giving the relative position of keywords.
> 
> Like , i want to search for "Indian health" . I want these terms to  
> exactly come next to each other , any other order is considered as false  
> result.  
> Is this possible using elasticsearch ?
> 
> Thanks  
> Vineeth
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Randall\_McRee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randall_mcree/32/47177_2.png) [@Randall\_McRee](https://discuss.elastic.co/u/Randall_McRee)\
**Post date:** [August 28, 2013, 4:36pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/3 "2013-08-28T16:36:11Z")

</div>

Its called a phrase query.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wed, Aug 28, 2013 at 9:29 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:

> Hi ,
> 
> Is it possible to search giving the relative position of keywords.
> 
> Like , i want to search for "Indian health" . I want these terms to  
> exactly come next to each other , any other order is considered as false  
> result.  
> Is this possible using elasticsearch ?
> 
> Thanks  
> Vineeth
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ban\_Mido](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Ban\_Mido](https://discuss.elastic.co/u/Ban_Mido)\
**Post date:** [August 28, 2013, 4:38pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/4 "2013-08-28T16:38:18Z")

</div>

Thanks all.

That really helped

On Wed, Aug 28, 2013 at 10:06 PM, Randall McRee [randall.mcree@gmail.com](mailto:randall.mcree@gmail.com)wrote:

> Its called a phrase query.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query/)
> 
> On Wed, Aug 28, 2013 at 9:29 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:
> 
> > Hi ,
> > 
> > Is it possible to search giving the relative position of keywords.
> > 
> > Like , i want to search for "Indian health" . I want these terms to  
> > exactly come next to each other , any other order is considered as false  
> > result.  
> > Is this possible using elasticsearch ?
> > 
> > Thanks  
> > Vineeth
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ban\_Mido](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Ban\_Mido](https://discuss.elastic.co/u/Ban_Mido)\
**Post date:** [August 28, 2013, 4:43pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/5 "2013-08-28T16:43:55Z")

</div>

One more question.

Is it possible to tell the relative position between the tokens.  
Like

Is (TOKEN)[0-3] going home

Here "home" should be immediately followed by going but there can be  
maximum of 3 tokens between is and going.

On Wed, Aug 28, 2013 at 10:08 PM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:

> Thanks all.
> 
> That really helped
> 
> On Wed, Aug 28, 2013 at 10:06 PM, Randall McRee [randall.mcree@gmail.com](mailto:randall.mcree@gmail.com)wrote:
> 
> > Its called a phrase query.  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query/)
> > 
> > On Wed, Aug 28, 2013 at 9:29 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:
> > 
> > > Hi ,
> > > 
> > > Is it possible to search giving the relative position of keywords.
> > > 
> > > Like , i want to search for "Indian health" . I want these terms to  
> > > exactly come next to each other , any other order is considered as false  
> > > result.  
> > > Is this possible using elasticsearch ?
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Randall\_McRee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randall_mcree/32/47177_2.png) [@Randall\_McRee](https://discuss.elastic.co/u/Randall_McRee)\
**Post date:** [August 28, 2013, 4:56pm UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/6 "2013-08-28T16:56:12Z")

</div>

Well, that is what "slop" is in that documentation you were pointed to.

Note that "is" can be a stopword, By definition, stopwords are not in the  
index. So be careful that you understand how your analyzer is actually  
indexing what you are giving it.

Spend some time understanding the query explanation that (optionally) comes  
back from each hit.

On Wed, Aug 28, 2013 at 9:43 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:

> One more question.
> 
> Is it possible to tell the relative position between the tokens.  
> Like
> 
> Is (TOKEN)[0-3] going home
> 
> Here "home" should be immediately followed by going but there can be  
> maximum of 3 tokens between is and going.
> 
> On Wed, Aug 28, 2013 at 10:08 PM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:
> 
> > Thanks all.
> > 
> > That really helped
> > 
> > On Wed, Aug 28, 2013 at 10:06 PM, Randall McRee [randall.mcree@gmail.com](mailto:randall.mcree@gmail.com)wrote:
> > 
> > > Its called a phrase query.  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query/)
> > > 
> > > On Wed, Aug 28, 2013 at 9:29 AM, Ban Mido [banmidobeyondtime@gmail.com](mailto:banmidobeyondtime@gmail.com)wrote:
> > > 
> > > > Hi ,
> > > > 
> > > > Is it possible to search giving the relative position of keywords.
> > > > 
> > > > Like , i want to search for "Indian health" . I want these terms to  
> > > > exactly come next to each other , any other order is considered as false  
> > > > result.  
> > > > Is this possible using elasticsearch ?
> > > > 
> > > > Thanks  
> > > > Vineeth
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:19am UTC](https://discuss.elastic.co/t/search-based-on-relative-position/13372/7 "2017-07-06T02:19:14Z")

</div>


