# Relaxed phrase Search

**URL:** <https://discuss.elastic.co/t/relaxed-phrase-search/184817>\
**Category:** Elasticsearch\
**Created:** [June 7, 2019, 10:00pm UTC](https://discuss.elastic.co/t/relaxed-phrase-search/184817 "2019-06-07T22:00:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [June 7, 2019, 10:00pm UTC](https://discuss.elastic.co/t/relaxed-phrase-search/184817/1 "2019-06-07T22:00:13Z")

</div>

Anyone in this community tried implementing relaxed phrase search as explained in below example -

> d1- "Hi, this is Imran from Microsoft"  
> d2 - "Microsoft is where the employee named Imran works"

Say in above texts I want to perform a search like this -

> Query: Imran BEFORE/2 Microsoft  
> Meaning of the query - Search for sentences where we have Imran and Microsoft and the maximum words allowed between them is 2.  
> Result: d1

Another example -

> Query: Imran AFTER/7 Microsoft  
> Meaning of the query - Search for sentences where we have Imran and Microsoft and the maximum words allowed between them is 2.  
> Result: d2

I can share more examples if needed  
Thanks  
Imran

---

<div class="post-metadata">

**Author:** ![whatgeorgemade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whatgeorgemade/32/103246_2.png) [@whatgeorgemade](https://discuss.elastic.co/u/whatgeorgemade)\
**Post date:** [June 8, 2019, 5:39pm UTC](https://discuss.elastic.co/t/relaxed-phrase-search/184817/2 "2019-06-08T17:39:45Z")

</div>

Have a look at using a phrase query with the slop parameter. Using a large value for slop may end up returning lots of false positives though.

---

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [June 8, 2019, 9:00pm UTC](https://discuss.elastic.co/t/relaxed-phrase-search/184817/3 "2019-06-08T21:00:57Z")

</div>

Sounds great - [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html)

---

<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, 2019, 9:01pm UTC](https://discuss.elastic.co/t/relaxed-phrase-search/184817/4 "2019-07-06T21:01:08Z")

</div>

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