# Preventing phrase search from matching across sentence boundaries

**URL:** <https://discuss.elastic.co/t/preventing-phrase-search-from-matching-across-sentence-boundaries/9676>\
**Category:** Elasticsearch\
**Created:** [November 12, 2012, 3:13pm UTC](https://discuss.elastic.co/t/preventing-phrase-search-from-matching-across-sentence-boundaries/9676 "2012-11-12T15:13:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_Hughes](https://avatars.discourse-cdn.com/v4/letter/r/e36b37/32.png) [@Robin\_Hughes](https://discuss.elastic.co/u/Robin_Hughes)\
**Post date:** [November 12, 2012, 3:13pm UTC](https://discuss.elastic.co/t/preventing-phrase-search-from-matching-across-sentence-boundaries/9676/1 "2012-11-12T15:13:28Z")

</div>

Hi

I'd like to know if there is a way to configure analysis so periods and  
commas result in a position increment. The purpose of this is to that  
phrase queries will not match across sentence boundaries.

i.e. a span\_term query with terms "one" and "two" with a slop of zero would  
match a document containing "one two" but not one containing "one. two"

Regards

Robin

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [November 12, 2012, 10:42pm UTC](https://discuss.elastic.co/t/preventing-phrase-search-from-matching-across-sentence-boundaries/9676/2 "2012-11-12T22:42:33Z")

</div>

Hi Robin,

I can't think of an analysis component that does this out-of-box but it is  
a requirement that comes up often. If you're comfortable creating a  
TokenFilter yourself then you could write one that inflates the position  
increment at whatever characters are of interest. Alternatively you could  
break up your data before indexing it into Elasticsearch, so each sentence  
or part of a sentence was a new value. Multiple values for a field are  
indexed with large position increments in between them.

On Tuesday, November 13, 2012 4:13:28 AM UTC+13, Robin Hughes wrote:

> Hi
> 
> I'd like to know if there is a way to configure analysis so periods and  
> commas result in a position increment. The purpose of this is to that  
> phrase queries will not match across sentence boundaries.
> 
> i.e. a span\_term query with terms "one" and "two" with a slop of zero  
> would match a document containing "one two" but not one containing "one.  
> two"
> 
> Regards
> 
> Robin

--

---

<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, 3:04am UTC](https://discuss.elastic.co/t/preventing-phrase-search-from-matching-across-sentence-boundaries/9676/3 "2017-07-06T03:04:40Z")

</div>


