# Near by queries within the boundary of sentences

**URL:** <https://discuss.elastic.co/t/near-by-queries-within-the-boundary-of-sentences/24133>\
**Category:** Elasticsearch\
**Created:** [June 22, 2015, 10:34pm UTC](https://discuss.elastic.co/t/near-by-queries-within-the-boundary-of-sentences/24133 "2015-06-22T22:34:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reza\_sadoddin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reza_sadoddin/32/3437_2.png) [@reza\_sadoddin](https://discuss.elastic.co/u/reza_sadoddin)\
**Post date:** [June 22, 2015, 10:34pm UTC](https://discuss.elastic.co/t/near-by-queries-within-the-boundary-of-sentences/24133/1 "2015-06-22T22:34:26Z")

</div>

I want to run near by query so that the terms are not returned as results if they are within two separate sentences. How can I specify this in Elasticsearch?

I am using wikipedia river plugin to index data.  
Thanks for sharing your thoughts.

~R

---

<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:** [June 23, 2015, 2:45am UTC](https://discuss.elastic.co/t/near-by-queries-within-the-boundary-of-sentences/24133/2 "2015-06-23T02:45:46Z")

</div>

One solution is to index each sentence individually as a separate instance  
of a field. You would need to use the position increment gap setting to  
artificially add a large gap between sentences. Then when you search with a  
near query, you need to provide a slop less then the gap increment used.

Cheers,

Ivan

---

<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:06am UTC](https://discuss.elastic.co/t/near-by-queries-within-the-boundary-of-sentences/24133/3 "2017-07-06T00:06:04Z")

</div>


