Unified highlighter with function_score

Hello, I have a query to search for the acronym: pin and "Personal Identification Number", with "auto_generate_synonyms_phrase_query": true
I don't want results with 3 words Personal, Identification, Number highlighted separately. I also use function_score to apply a function for date
But the query below returns results with one of these 3 words highlighted:

POST /test/_search
{
	"query": {
		"function_score": {
			"query": {
				"bool": {
					"minimum_should_match": 1,
					"should": [
						{
							"multi_match": {
								"query": "pin",
								"fields": [
								  "title",
									"text"
								],
								"operator": "AND",
								"auto_generate_synonyms_phrase_query": true
							}
						}
					]
				}
			},
			"score_mode": "multiply",
			"functions": [
				{
					"filter": {
						"match": {
							"document_type": "actu"
						}
					},
					"weight": 3,
					"script_score": {
						"script": {
							"source": "decayDateGauss('2023-02-10', '30d', '0', 0.5, doc['sort_date'].value)"
						}
					}
				}
			]
		}
	},
	"_source": [
		"sort_date"
	],
	"highlight": {
		"fields": {
			"title": {
				"number_of_fragments": 0,
				"type": "unified",
				"pre_tags": [
					"<hit>"
				],
				"post_tags": [
					"</hit>"
				],
				"fragment_size": 0,
				"no_match_size": 3000000,
				"order": "none"
			},
			"text": {
				"number_of_fragments": 0,
				"type": "unified",
				"pre_tags": [
					"<hit>"
				],
				"post_tags": [
					"</hit>"
				],
				"fragment_size": 0,
				"no_match_size": 3000000,
				"order": "score"
			}
		}
	},
	"size": 20,
	"from": 0
}

If I remove function_score, the unified highlighting works well. How can I correct the query?

I got a solution with highlight_query, I copied the object query.bool and pasted it into the highlight_query

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