# Proximity in Query

**URL:** <https://discuss.elastic.co/t/proximity-in-query/9433>\
**Category:** Elasticsearch\
**Created:** [October 22, 2012, 6:05am UTC](https://discuss.elastic.co/t/proximity-in-query/9433 "2012-10-22T06:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kartavya](https://avatars.discourse-cdn.com/v4/letter/k/65b543/32.png) [@Kartavya](https://discuss.elastic.co/u/Kartavya)\
**Post date:** [October 22, 2012, 6:05am UTC](https://discuss.elastic.co/t/proximity-in-query/9433/1 "2012-10-22T06:05:44Z")

</div>

Hi

I have implemented proximity query as below.  
{  
"query" : {  
"bool" : {  
"should" : {  
"query\_string" : {  
"field" : "Title",  
"query" : ""ELASTIC SEARCH"~3"  
}  
}}  
}  
}

How can I implement it like below

{  
"query" : {  
"bool" : {  
"should" : {  
"field" : {"Title" : ""ELASTIC SEARCH OR LUCENE SEARCH OR (A AND  
B)"~3" }  
}  
}  
}  
}

Please Suggest.

Thanks,

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [October 22, 2012, 5:02pm UTC](https://discuss.elastic.co/t/proximity-in-query/9433/2 "2012-10-22T17:02:04Z")

</div>

I am not sure I understand what you are trying to achieve. Could you,  
perhaps, give an example? Would something like this work for you?

"ELASTIC SEARCH"~3 OR "LUCENE SEARCH"~3 OR (A AND B) ?

On Monday, October 22, 2012 2:06:07 AM UTC-4, kartavya wrote:

> Hi
> 
> I have implemented proximity query as below.  
> {  
> "query" : {  
> "bool" : {  
> "should" : {  
> "query\_string" : {  
> "field" : "Title",  
> "query" : ""ELASTIC SEARCH"~3"  
> }  
> }}  
> }  
> }
> 
> How can I implement it like below
> 
> {  
> "query" : {  
> "bool" : {  
> "should" : {  
> "field" : {"Title" : ""ELASTIC SEARCH OR LUCENE SEARCH OR (A AND  
> B)"~3" }  
> }  
> }  
> }  
> }
> 
> Please Suggest.
> 
> Thanks,

--

---

<div class="post-metadata">

**Author:** ![balaa\_gs](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@balaa\_gs](https://discuss.elastic.co/u/balaa_gs)\
**Post date:** [May 19, 2015, 9:49am UTC](https://discuss.elastic.co/t/proximity-in-query/9433/3 "2015-05-19T09:49:37Z")

</div>

Hi

```
 i am having the same doubt which you have asked.

 is there any possibility to work like below query

 ((A OR B) AND (C OR D)~5)

```

Ex:  
my expected result = (A OR B) within 5 words of (C OR D)

```
   if A is the result of first group, C is the result of 2nd group, then A should be with in 5 words of C.
```

---

<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, 12:13am UTC](https://discuss.elastic.co/t/proximity-in-query/9433/4 "2017-07-06T00:13:22Z")

</div>


