# Query String query limited to sentence

**URL:** <https://discuss.elastic.co/t/query-string-query-limited-to-sentence/199387>\
**Category:** Elasticsearch\
**Created:** [September 13, 2019, 8:22am UTC](https://discuss.elastic.co/t/query-string-query-limited-to-sentence/199387 "2019-09-13T08:22:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philv](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@philv](https://discuss.elastic.co/u/philv)\
**Post date:** [September 13, 2019, 8:22am UTC](https://discuss.elastic.co/t/query-string-query-limited-to-sentence/199387/1 "2019-09-13T08:22:46Z")

</div>

Hi All,

I have a use case where I'd like to be able to use the mini language , or at least the boolean operator parser of the query string query on a document level or a sentence level. I can define sentences easily enough using a large position\_increment\_gap between these at index time, and thus constrain phrase queries with a slop to be within the confines of a single sentence, I can then search for co occurrence using a span query.  
But I'd like to be able to use the parser logic for boolean operators that lucene provides , so we can do richer queries such as

> man OR person

> X AND ( Y OR Z)  
> etc

and have that only hit if the matches are all within the same sentence.

I was hoping to avoid having to write a parser that took the lucene mini language syntax and converted it to span queries.

Or perhaps there's a better way to achieve this with existing techniques?

I wondered whether there was a clause that I'm missing that would constrain all hit tokens to be within a certain distance of each other. I'm talking not about slop within a phrase query, but a global slop over all tokens matched. That way all could be forced to be within a sentence.

Grateful for any suggestions !

Best,  
Phil

---

<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:** [October 11, 2019, 8:22am UTC](https://discuss.elastic.co/t/query-string-query-limited-to-sentence/199387/2 "2019-10-11T08:22:46Z")

</div>

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