Highlights are empty in some cases

I have an aggregation pipeline containing a “search” stage, in which I’m looking for client name (and some other fields, but let’s focus on the name here). It looks like this :

            "$search": {
                "index": "index_clients",
                "highlight": {
                    "path": ["name", "firstName", "streetName", "locality", "customerId"]
                },
                "compound": {
                    "should": [
                        {
                            "text": {
                                "path": "name",
                                "query": "{{search-string}}",
                                "fuzzy": {"maxEdits": 1}
                                "score": { "boost": { "value": 3 } }
                            }
                        },
                        {
                            "autocomplete": {
                                "path": "name",
                                "query": "{{search-string}}",
                                "score": { "boost": { "value": 3 } }
                            }
                        },

You can notice that I use both the “text” and “autocomplete” operator. This is the workaround suggested by the official Mongodb documentation, because if I use only the autocomplete operator, exact matches will have a lower score than non-exact matches (which is a non-sense, so I don’t want that).

A bit further in my pipeline, I have a “project” stage in which I would like to add the highlights metadata:

            "$project": {
                "_id": 0,
                "object_id": "$customerId",
                "object_infos": {
                    "$concat": [
                        "$customerId", 
                        " - ", 
                        "$name",  
                        " ", 
                        "$locality"
                    ]
                },
                "score": { "$meta": "searchScore"},
                "highlights": { "$meta": "searchHighlights" }
            }

I’ll describe my problem with a concreate example : I search for clients whose name begins by “Pla”. I have many results in output, including those 3 ones: “Plak”, “Placide”, “Planque”.

For the first result, the highlights metadata are correctly filled, and I can clearly identify that there was a match on “Plak”. However, for the 2 other results, the highlights are not present (empty array).

From this example, as well as some others that I did, I came to the following conclusion:

  • If the result is a 100% exact match > highlights are well returned
  • If the result is an exact match thanks to the fuzzy option (difference in 1 character) > highlights are returned (in my example, it explains why “Plak” was returned)
  • If the result is returned thanks to the autocomplete operator > highlight is not returned.

According to the highlight documentation, there’s a note saying :

To highlight the autocomplete indexed version of a path, the autocomplete operator must be the only operator that uses that path in the query.

This probably explains why I have the issue. So currently the documentation recommends to use both text and autocomplete operators in order to have better scores for exact matches, but on the other hand it forbids to have those 2 operators in the same time if we want the highlights, which is a bit inconsistent. Is there a chance that this will be fixed soon ?