# Unified highlighter with function\_score

**URL:** <https://discuss.elastic.co/t/unified-highlighter-with-function-score/325281>\
**Category:** Elasticsearch\
**Created:** [February 10, 2023, 3:44pm UTC](https://discuss.elastic.co/t/unified-highlighter-with-function-score/325281 "2023-02-10T15:44:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wonder\_Garance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wonder_garance/32/91180_2.png) [@Wonder\_Garance](https://discuss.elastic.co/u/Wonder_Garance)\
**Post date:** [February 10, 2023, 3:44pm UTC](https://discuss.elastic.co/t/unified-highlighter-with-function-score/325281/1 "2023-02-10T15:44:10Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Wonder\_Garance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wonder_garance/32/91180_2.png) [@Wonder\_Garance](https://discuss.elastic.co/u/Wonder_Garance)\
**Post date:** [February 13, 2023, 8:18pm UTC](https://discuss.elastic.co/t/unified-highlighter-with-function-score/325281/2 "2023-02-13T20:18:40Z")

</div>

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

---

<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 13, 2023, 8:18pm UTC](https://discuss.elastic.co/t/unified-highlighter-with-function-score/325281/3 "2023-03-13T20:18:47Z")

</div>

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