Hi,
(ElasticSearch 7.8.0)
it looks like script_score queries in conjunction with fvh highligher and matched_fields doesn't work. I don't know if i'm missing something, but i couldn't find any do's/don'ts in the documentation reg. this:
Mapping:
PUT test
{
"settings": {
"index": {
"max_ngram_diff": 20
},
"analysis": {
"filter": {
"ngram_2_to_12": {
"type": "ngram",
"min_gram": "2",
"max_gram": "12"
}
},
"analyzer": {
"my_lowercase": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
},
"my_ngram": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"ngram_2_to_12"
]
}
}
}
},
"mappings": {
"properties": {
"message": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"ngram": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "my_ngram",
"search_analyzer": "my_lowercase"
}
}
},
"timestamp": {
"type": "date",
"format": "date_time"
}
}
}
}
Docs:
POST test/_doc
{
"message": "just a test please ignore",
"timestamp": "2020-09-17T06:49:20.488Z"
}
POST test/_doc
{
"message": "testing again",
"timestamp": "2020-09-16T12:00:00.0Z"
}
Works as expected using multi_match query:
GET /test/_search
{
"query": {
"multi_match": {
"query": "es",
"fields": ["message", "message.ngram"]
}
},
"highlight": {
"number_of_fragments": 1,
"fields": {
"message": {
"type": "fvh",
"matched_fields": ["message", "message.ngram"]
}
}
}
}
Doesn't work when switching to script_score query - no highlights are returned:
GET /test/_search
{
"query": {
"script_score": {
"query": {
"multi_match": {
"query": "es",
"fields": ["message", "message.ngram"]
}
},
"script": {
"source": "1"
}
}
},
"highlight": {
"number_of_fragments": 1,
"fields": {
"message": {
"type": "fvh",
"matched_fields": ["message", "message.ngram"]
}
}
}
}
It doesn't matter if searching for "test" or "es", in either case no highlights are returned.