# Does early termination (sorted index) kick in in this case?

**URL:** <https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370>\
**Category:** Elasticsearch\
**Created:** [July 31, 2020, 4:16pm UTC](https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370 "2020-07-31T16:16:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmlucjav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmlucjav/32/5870_2.png) [@jmlucjav](https://discuss.elastic.co/u/jmlucjav)\
**Post date:** [July 31, 2020, 4:16pm UTC](https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370/1 "2020-07-31T16:16:29Z")

</div>

I have such an index (ES 7.4):

```auto
    "index": {
        "sort.field": "date",
        "sort.order": "desc",

```

And I query like this:

```auto
    {
    "sort": [
        "_score",
        {
            "date": {
                "order": "desc"
            }
        }
    ],
    "track_total_hits": false,
    "query": {
                    "multi_match": {
                        "query": "banana",
                        "fields": [
                            "title^2"                     
                        ]
                    }
        }
    }
    }

```

And important detail, title field is like this:

```auto
            "title": {
                "type": "text",
                "analyzer": "custom_text",
                "search_analyzer": "custom_search",
                "similarity": "boolean"
            },

```

so its using boolean similarity. As such max score for docs will be 2 (boost value). Even if we sort by score first, by date later, as the max score is known, early termination could be used here. But I cannot assert by looking at my experiments, as I have only a very small index to test.

So, is it being used?

thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 3, 2020, 9:42am UTC](https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370/2 "2020-08-03T09:42:17Z")

</div>

If you sort by score, then index sorting will not apply.

What could however still apply is the block max-WAND. See [https://www.elastic.co/blog/faster-retrieval-of-top-hits-in-elasticsearch-with-block-max-wand](https://www.elastic.co/blog/faster-retrieval-of-top-hits-in-elasticsearch-with-block-max-wand)

---

<div class="post-metadata">

**Author:** ![jmlucjav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmlucjav/32/5870_2.png) [@jmlucjav](https://discuss.elastic.co/u/jmlucjav)\
**Post date:** [August 3, 2020, 11:27am UTC](https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370/3 "2020-08-03T11:27:34Z")

</div>

ok, makes sense...

Yeah, max-WAND would apply but this would happen even if the index was date-sorted.

thanks!

---

<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:** [August 31, 2020, 11:27am UTC](https://discuss.elastic.co/t/does-early-termination-sorted-index-kick-in-in-this-case/243370/4 "2020-08-31T11:27:36Z")

</div>

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