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:
{
"_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:
{
"_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:
"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:
{
"query": {
"bool": {
"should": [
{ "match": {
"name.autocomplete": {
"query": "jo"
}
} }
]
}
},
"highlight": {
"fields": {
"name.autocomplete": {}
}
}
}
Is this possible to do? thanks for any assitance.