# Script\_score query: fvh highlighter doesn't work

**URL:** <https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926>\
**Category:** Elasticsearch\
**Created:** [September 17, 2020, 7:34am UTC](https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926 "2020-09-17T07:34:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@grob](https://discuss.elastic.co/u/grob)\
**Post date:** [September 17, 2020, 7:34am UTC](https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926/1 "2020-09-17T07:34:56Z")

</div>

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:**

```auto
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:**

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

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

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

---

<div class="post-metadata">

**Author:** ![grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@grob](https://discuss.elastic.co/u/grob)\
**Post date:** [September 21, 2020, 6:49am UTC](https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926/2 "2020-09-21T06:49:32Z")

</div>

Update: upgrading to 7.9.1 didn't solve the issue

---

<div class="post-metadata">

**Author:** ![grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@grob](https://discuss.elastic.co/u/grob)\
**Post date:** [October 13, 2020, 8:50am UTC](https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926/3 "2020-10-13T08:50:03Z")

</div>

Fwiw, found a solution: `fvh` highlighter works when passing the query wrapped by the `script_score` query as `highlight_query` option. It's a bit hidden in the documentation, the description for [highlight\_query](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#highlighting-settings) states:

> This is especially useful if you use a rescore query because those are not taken into account by highlighting by default.

---

<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:** [November 10, 2020, 8:50am UTC](https://discuss.elastic.co/t/script-score-query-fvh-highlighter-doesnt-work/248926/4 "2020-11-10T08:50:37Z")

</div>

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