# Highlighting on ngram search

**URL:** <https://discuss.elastic.co/t/highlighting-on-ngram-search/220257>\
**Category:** Elasticsearch\
**Created:** [February 20, 2020, 7:27pm UTC](https://discuss.elastic.co/t/highlighting-on-ngram-search/220257 "2020-02-20T19:27:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman731](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@roman731](https://discuss.elastic.co/u/roman731)\
**Post date:** [February 20, 2020, 7:27pm UTC](https://discuss.elastic.co/t/highlighting-on-ngram-search/220257/1 "2020-02-20T19:27:31Z")

</div>

Hello, I'm using ES7.5 and am trying to get highlighting to work on my ngram search (search results are working as expected).

Currently I have a bunch of documents with a name field, and when i do a partial search with ngrams, and it's highlighting the entire word and not the substring the user is entering.

For example, say I have names: Joe Foo, John Bar

If I query "Jo", I get back the following:

```auto
{
  "_source": {
     "name": "Joe Foo"
   },
   "highlight": {
      "name.ngram": [
        "<em>Joe</em>Foo"
      ]
   }
}, {
  "_source": {
     "name": "John Bar"
   },
   "highlight": {
      "name.ngram": [
        "<em>John</em>Bar"
      ]
   }
}

```

What I actually want:

```auto
{
  "_source": {
     "name": "Joe Foo"
   },
   "highlight": {
      "name.ngram": [
        "<em>Jo</em>e Foo"
      ]
   }
}, {
  "_source": {
     "name": "John Bar"
   },
   "highlight": {
      "name.ngram": [
        "<em>Jo</em>hn Bar"
      ]
   }
}

```

Here is my mapping:

```auto
"settings": {
    "max_ngram_diff": 50,
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "ngram",
          "min_gram": 1,
          "max_gram": 50
        }
      },
      "analyzer": {
        "autocomplete_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": ["lowercase", "autocomplete_filter"]
        },
        "lowercase_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword",
        "fields": {
          "autocomplete": {
            "type": "text",
            "analyzer": "autocomplete_analyzer",
            "search_analyzer": "lowercase_analyzer"
          }
        }
      }
    }
  }

```

And the query I am executing:

```auto
{
	"query": {
		"bool": {
			"should": [
				{ "match": {
					"name.autocomplete": {
						"query": "jo"
					}
				} }
			]
		}
	},
  "highlight": {
    "fields": {
      "name.autocomplete": {} 
    }
  }
}

```

Is this possible to do? thanks for any assitance.

---

<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:** [March 19, 2020, 7:27pm UTC](https://discuss.elastic.co/t/highlighting-on-ngram-search/220257/2 "2020-03-19T19:27:34Z")

</div>

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