# Highlighting issue with fuzzy query with edge\_ngram tokens

**URL:** <https://discuss.elastic.co/t/highlighting-issue-with-fuzzy-query-with-edge-ngram-tokens/362345>\
**Category:** Elasticsearch\
**Created:** [July 2, 2024, 7:08am UTC](https://discuss.elastic.co/t/highlighting-issue-with-fuzzy-query-with-edge-ngram-tokens/362345 "2024-07-02T07:08:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lschnei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lschnei/32/51893_2.png) [@lschnei](https://discuss.elastic.co/u/lschnei)\
**Post date:** [July 2, 2024, 7:08am UTC](https://discuss.elastic.co/t/highlighting-issue-with-fuzzy-query-with-edge-ngram-tokens/362345/1 "2024-07-02T07:08:35Z")

</div>

I couldn’t find a relevant example, so here’s my issue:

I’m developing a search-as-you-type feature using edge\_ngram tokens, which allows for spelling mistakes (fuzzy queries) while highlighting the current edge\_ngram token being matched.

The problem arises with exact matches: the highlight appears one character ahead due to the fuzzy component. For example, with a field value of “ **37751** ” and a query of “ **3775** ”, the highlight shows “ **37751** ” because of the fuzziness. The fuzzy query seems to prioritize the resulting longer token, causing it to be highlighted.

I’ve tried adjusting the highlights parameter, specifically setting the fragment\_size to the length of the query, but the issue persists.

Can you help me resolve this?

For reproducibility, here are my mappings, settings, and query. Thanks in advance.

**Settings**

```
   {"index": {"max_ngram_diff": 10},
    "analysis": {

        "analyzer": {
            "autocomplete": {
                "tokenizer": "autocomplete",
                "filter": ["lowercase", "asciifolding"],
            },
            "autocomplete_search": {
                "tokenizer": "standard",
                "filter": ["lowercase", "asciifolding"],
        },
        "tokenizer": {
            "autocomplete": {
                "type": "edge_ngram",
                "min_gram": 2,
                "max_gram": 10,
                "token_chars": ["letter", "digit"],
            },
        },
    }

```

**Mappings**

```
{
    "properties": {
        "A_ID": {"type": "text", "copy_to": "autocomplete_text"},
        "B_ID": {
            "type": "text",
            "copy_to": "autocomplete_text",
        },
        "name": {
            "type": "text",
            "copy_to": "autocomplete_text",
        },
        "autocomplete_text": {
            "type": "text",
            "analyzer": "autocomplete",
            "search_analyzer": "autocomplete_search",
        },
    }
}

```

**Query**

```
query= "3775"
 
bool = {
    "bool": {
        "should": [
            {
                "match": {
                    "autocomplete_text": {
                        "query": query,
                        "operator": "and",
                        "boost": 10,
                    }
                }
            },
            {
                "match": {
                    "autocomplete_text": {
                        "query": query,
                        "operator": "and",
                        "fuzziness": "AUTO",
                    }
                },
            },
        ],
    }
}
 
highlight = {
    "fields": [
        {
            "autocomplete_text": {
                "fragment_size": len(query),
            }
        }
    ],
}

```
