### Elasticsearch Version

v8.5.2

### Installed Plugins

mapper-annotated-text

### Java Version

_bundled_

### OS Version

Linux 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

### Problem Description

Hi,

We use the `mapper-annotated-text` plugin in production to tag named-entities and found an particularly bad behavior during highlighting.

Basically, if we have a text `aaaa [bbbb cccc](annotated) dddd`, and search for `bbbb annotated` we'll get the highlight `aaaa [bbbb](_hit_term=bbbb) cccc dddd` where we'd expect `bbbb cccc` due to `annotated` being in the query too.

On the other hand, searching for `cccc annotated` produces the expected result of `aaaa [bbbb cccc](_hit_term=annotated&annotated) dddd`.

This happens because the annotation process receives the passage matches sorted by ascending offset order, and when a match overlaps with a previously seen one, it ignores it. So in the first case, it sees `bbbb` first and when it sees `annotated` it discards it because it overlaps with `bbbb`. On the latter case, `cccc` is the one discarded since it appears later in the list of offsets.

We've prototype a fix in [this branch](https://github.com/jusbrasil/elasticsearch/commit/aef49112d8795fac3d0425e2f810f1820c9a3d5e) and would be glad to iterate on it and advance with a PR if this is considered as an issue.

### Steps to Reproduce

```
PUT example
{
  "mappings": {
    "properties": {
      "body": {
        "type": "annotated_text"
      }
    }
  }
}
POST example/_doc
{
  "body": "aaaa [bbbb cccc](annotated) dddd"
}
POST example/_search
{
  "query": {
    "match_all": {}
  },
  "highlight": {
    "type": "annotated",
    "order": "score",
    "fields": {
      "body": {
        "highlight_query": {
          "bool": {
            "must": {
              "match": {
                "body": {
                  "query": "bbbb annotated"
                }
              }
            }
          }
        }
      }
    }
  }
}
```

### Logs (if relevant)

_No response_
plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextHighlighterTests.java
for (int i = 0; i < snippets.length; i++) {
                    assertEquals(expectedPassages[i], snippets[i].getText());
                }
            }
        }
    }
    public void testAnnotatedTextStructuredMatch() throws Exception {
        
        
        
        String url = "https://en.wikipedia.org/wiki/Key_Word_in_Context";
        String encodedUrl = URLEncoder.encode(url, "UTF-8");
        String annotatedWord = "[highlighting](" + encodedUrl + ")";
        String highlightedAnnotatedWord = "[highlighting]("
            + AnnotatedPassageFormatter.SEARCH_HIT_TYPE
            + "="
            + encodedUrl
            + "&"
            + encodedUrl
            + ")";
        final String[] markedUpInputs = {
            "This is a test. Just a test1 " + annotatedWord + " from [annotated](bar) highlighter.",
            "This is the second " + annotatedWord + " value to perform highlighting on a longer text that gets scored lower." };
        String[] expectedPassages = {
            "This is a test. Just a test1 " + highlightedAnnotatedWord + " from [annotated](bar) highlighter.",
            "This is the second "
                + highlightedAnnotatedWord
                + " value to perform highlighting on a"
                + " longer text that gets scored lower." };
        Query query = new TermQuery(new Term("text", url));