Unusual highlight results from compound query using filter, should, and autocomplete

I ran into a strange issue where highlighted results for a compound query don’t match what I’d expect. It could be that I missed something in the documentation. I did my best to come up with a minimal reproducible example, which I’ll detail here. To start with, I created a collection with a single document.

{
  "_id": {
    "$oid": "65a1dfc3c95fdaedc8a8ba94"
  },
  "key1": "123456",
  "key2": "12345678",
  "key3": "value3"
}

The search index for this collection

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "key1": {
        "type": "string"
      },
      "key2": {
        "maxGrams": 6,
        "minGrams": 2,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      },
      "key3": {
        "maxGrams": 6,
        "minGrams": 2,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      }
    }
  }
}

The aggregation pipeline that I ran against the one-document collection using ‘testIndex’ created above. The goal of this pipeline is to filter for any documents where “key1” matches “123456”. Then I’d like to return any document where either “key2” or “key3” matches a search string.

[
  {
    $search:
      {
        index: "testIndex",
        compound: {
          filter: [
            {
              text: {
                path: "key1",
                query: "123456",
              },
            },
          ],
          should: [
            {
              autocomplete: {
                path: "key2",
                query: "value"
              }
            },
            {
              autocomplete: {
                path: "key3",
                query: "value",
              },
            },
          ],
          "minimumShouldMatch": 1
        },
        highlight: {
          path: ["key2", "key3"]
        },
      },
  },
  {
    $project:
      {
        highlights: {
          $meta: "searchHighlights",
        },
      },
  },
]

The result I get

{
  "_id": {
    "$oid": "65a1dfc3c95fdaedc8a8ba94"
  },
  "highlights": [
    {
      "score": 1.4151861667633057,
      "path": "key3",
      "texts": [
        {
          "value": "value3",
          "type": "hit"
        }
      ]
    },
    {
      "score": 1.113616943359375,
      "path": "key2",
      "texts": [
        {
          "value": "12345678",
          "type": "hit"
        }
      ]
    }
  ]
}

To me, this doesn’t make sense. The filter is against the “key1” field, but the text query from the filter is matching against the “key2” field. For the above result, I’d expect only the “key3” match to be included in the highlights, because “key3” matches “value” but “key2” does not match “value”.

Has anyone come across a situation like this? Do I need to structure my aggregation pipeline or my index differently?

Thanks for your help!

Bumping this thread. Anyone have any ideas? Right now, the workaround is to add extra processing to verify the highlights.