# Issue with ordered intervals queries

**URL:** <https://discuss.elastic.co/t/issue-with-ordered-intervals-queries/208110>\
**Category:** Elasticsearch\
**Created:** [November 15, 2019, 5:07pm UTC](https://discuss.elastic.co/t/issue-with-ordered-intervals-queries/208110 "2019-11-15T17:07:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bperalta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bperalta/32/57782_2.png) [@bperalta](https://discuss.elastic.co/u/bperalta)\
**Post date:** [November 15, 2019, 5:07pm UTC](https://discuss.elastic.co/t/issue-with-ordered-intervals-queries/208110/1 "2019-11-15T17:07:11Z")

</div>

Hello,  
we use elasticsearch 7.2.0 (but the problem also exists in 7.4.2) and we have some problems with intervals queries.

To reproduce our problem, create a simple index :

```
PUT intervals_tests
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "object": { "type": "text" }
    }
  }
}

```

Add that simple document :

```
{
    "object": "issue with intervals queries from search engine. So it's a big issue for us as we need to do ordered searches. Thank you to help us concerning that issue"
}

```

Execute that simple intervals query :

```
{
    "query": {
        "intervals": {
            "object": {
                "match": {
                    "query": "issue engine ordered",
                    "max_gaps": 1,
                    "ordered": true
                }
            }
        }
    },
    "highlight": {
        "type": "unified",
        "fields": {
            "object": {}
        }
    }
}

```

The document will match... but it would not...

If you execute the same query but with "ordered": false, the document will not match !

This error happen because the document contains 3 times the word "issue" (of course I don't know why...). If you delete any of the "issue" words, all is working fine.

To work around that, I use query like that :

```
{
    "query": {
        "intervals": {
            "object": {
                "match": {
                    "query": "issue engine ordered",
                    "max_gaps": 1,
                    "ordered": true,
                    "filter": {
                        "contained_by": {
                            "match": {
                                "query": "issue engine ordered",
                                "max_gaps": 1,
                                "ordered": false
                            }
                        }
                    }
                }
            }
        }
    },
    "explain": true,
    "highlight": {
        "type": "unified",
        "fields": {
            "object": {}
        }
    }
}

```

Am I doing something wrong ?  
Thank you for your help  
Bertrand

---

<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 13, 2019, 5:07pm UTC](https://discuss.elastic.co/t/issue-with-ordered-intervals-queries/208110/2 "2019-12-13T17:07:14Z")

</div>

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