Hello,
Env:
ES 7.15.0
PUT my-index-000001
{
"mappings": {
"properties": {
"my_field": {
"type": "search_as_you_type"
}
}
}
}
PUT my-index-000001/_doc/1?refresh
{
"my_field": "quick brown fox jump lazy dog"
}
I am trying to accomplish autocomplete and highlight at the same time. Something like algolia autocomplete
I took code from Search-as-you-type field type | Elasticsearch Guide [7.15] | Elastic and add a highlight section. The result is that highlighter works just for whole words. I am expecting that even partial prefix matches will be highlighted.
For example from this query:
GET my-index-000001/_search
{
"query": {
"multi_match": {
"query": "brow",
"type": "bool_prefix",
"fields": [
"my_field",
"my_field._2gram",
"my_field._3gram"
]
}
},
"highlight": {
"fields": {
"my_field": {
}
}
}
}
I would expect:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"my_field" : "quick brown fox jump lazy dog"
},
"highlight" : {
"my_field" : [
"quick <em>brow</em>n fox jump lazy dog"
]
}
}
]
}
}
Real result:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"my_field" : "quick brown fox jump lazy dog"
}
}
]
}
}
- I also tried "match_phrase_prefix" query but had no success.
- I also found some solutions with additional mapping with a separated ngram analyzer used just for highlighting, but it doesn't look like the right path to go.
- If I try to highlight on my_field._index_prefix result is strange
.
Is it possible to create it in this way?
Thanks.