# Interval query with filters to include in max gap?

**URL:** <https://discuss.elastic.co/t/interval-query-with-filters-to-include-in-max-gap/318346>\
**Category:** Elasticsearch\
**Created:** [November 7, 2022, 3:26pm UTC](https://discuss.elastic.co/t/interval-query-with-filters-to-include-in-max-gap/318346 "2022-11-07T15:26:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Broccolimon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/broccolimon/32/112889_2.png) [@Broccolimon](https://discuss.elastic.co/u/Broccolimon)\
**Post date:** [November 7, 2022, 3:26pm UTC](https://discuss.elastic.co/t/interval-query-with-filters-to-include-in-max-gap/318346/1 "2022-11-07T15:26:42Z")

</div>

Hey!  
I have a query that is looking for the terms "fox" and "brown" in an interval of 10 positions and i would like to filter any result with the word "quick" which is 5 position before interval start and 5 position after interval end , for example:

text: "The quick and smart fox is very brown " - should not return  
text: "the sad and smart fox is very brown " - should return

right now I'm writing it like this :

```auto
query ={
            "query": {
                "intervals":{ 
                    "title":{
                    "all_of": {
                        "ordered":False,
                        "intervals": [
                            {"match": { "query":"fox brown","ordered":False,"max_gaps":10,
                                       "filter":{'not_overlapping':{"match":{'query':'fox brown quick',"ordered":False,"max_gaps":20}}}}}
                          
                            ],
                                 }
                    }
            }
        }
}

```

Is there a better way to do it ? such that i will only need to use "quick" in the filter and to state the maximal gap (of pre and post interval) ?

---

<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:** [December 5, 2022, 3:27pm UTC](https://discuss.elastic.co/t/interval-query-with-filters-to-include-in-max-gap/318346/2 "2022-12-05T15:27:02Z")

</div>

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