# Exact phrase near other terms

**URL:** <https://discuss.elastic.co/t/exact-phrase-near-other-terms/268893>\
**Category:** Elasticsearch\
**Created:** [March 31, 2021, 10:20am UTC](https://discuss.elastic.co/t/exact-phrase-near-other-terms/268893 "2021-03-31T10:20:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rd8388](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rd8388](https://discuss.elastic.co/u/rd8388)\
**Post date:** [March 31, 2021, 10:20am UTC](https://discuss.elastic.co/t/exact-phrase-near-other-terms/268893/1 "2021-03-31T10:20:34Z")

</div>

Is there a way to search for one or more exact phrases near one or more other terms/phrases?

I'm using MatchPhrase with slop zero to find exact phrases fine and using Match to find two or more terms near each other but how do you combine the two please?

If a user entered...  
Surname(s): Duck Mouse  
Forename(s): Michael Donald  
The query should match documents that contain pairs from the specified forename(s) and surname(s). e.g. "Michael Mouse", "Michael Rupert Mouse" (with slop), "Donald Duck", "Michael Duck".  
The query should not match documents that contain "Duck Mouse".

If a user entered...  
Surnames(s): Jones  
Forename(s): **"Anne Marie"**  
The query should match documents that contain "Anne Marie" near Jones and not just Anne near Jones or Marie near Jones, because they have qualified "Anne Marie" as a phrase.

If they didn't qualify Anne Marie as a phrase then the query should match instances of each forename and surname pair.

I have the unqualified forename and surname pairs working fine.  
I am able to search for the exact phrase match fine.  
It is doing the exact phrase match for a qualified term AND that being near to another term I am not sure how to achieve.  
Potentially a user might want to specify qualified terms for both surname and forename and again I would want results where "fname1 fname2" is near "sname1 sname2".

---

<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:** [April 28, 2021, 10:21am UTC](https://discuss.elastic.co/t/exact-phrase-near-other-terms/268893/2 "2021-04-28T10:21:18Z")

</div>

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