# Highlighting of exact search with simple\_query\_string

**URL:** <https://discuss.elastic.co/t/highlighting-of-exact-search-with-simple-query-string/283292>\
**Category:** Elasticsearch\
**Created:** [September 3, 2021, 2:45pm UTC](https://discuss.elastic.co/t/highlighting-of-exact-search-with-simple-query-string/283292 "2021-09-03T14:45:46Z")\
**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:** [September 3, 2021, 2:45pm UTC](https://discuss.elastic.co/t/highlighting-of-exact-search-with-simple-query-string/283292/1 "2021-09-03T14:45:46Z")

</div>

I use Elasticsearch 7.9 and I want to highlight an exact search filed with simple query string query, for a document.  
The following query doesn't highlight words in the document, although these words are in the document.  
I tried to add this line in highlight.fields, but it changes nothing.

```auto
"text_html": {"number_of_fragments": 0}

```

How to correct it ? Thanks.

Configuration:

```auto
  "mappings": {
    "properties": {
      "text_html": {
        "type": "text",
        "analyzer": "english",
        "fields": {
          "exact": {
            "type": "text",
            "analyzer": "english_exact"
          }
        }
      }
    }
  }

```

And my query:

```auto
{
  "highlight": {
    "fields": {
      "text_html.exact": {"number_of_fragments": 0}
    }
  },
  "_source": [
    "id",
    "text_html"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "query": "\"use case\"",
            "fields": [
              "text_html"
            ],
            "quote_field_suffix": ".exact"
          }
        }
      ],
      "filter": [
        {
          "term": {"id": "case111"}
        }
      ]
    }
  }
}

```

---

<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:** [September 5, 2021, 12:53pm UTC](https://discuss.elastic.co/t/highlighting-of-exact-search-with-simple-query-string/283292/2 "2021-09-05T12:53:23Z")

</div>

I got a solution, in the query I added force\_source: true

```auto
"highlight": {
    "fields": {
      "text_html.exact": {
        force_source: true,
        "number_of_fragments": 0
        }
    }
  }

```

I found another solution to use the Fast Vector Highlighter (fvh), it works better for me.  
Here is the mapping:

```auto
{
    "properties": {
      "text_html": {
        "type": "text",
        "term_vector": "with_positions_offsets",
        "analyzer": "english",
        "fields": {
          "exact": {
            "type": "text",
            "term_vector": "with_positions_offsets",
            "analyzer": "english_exact"
          }
        }
      }
    }
  }

```

And the query with matched\_fields:

```auto
{
  "highlight": {
    "fields": {
      "text_html.exact": {
        "number_of_fragments": 0,
        "matched_fields": [
          "text_html",
          "text_html.exact"
        ],
        "type": "fvh"        
      }
    }
  },
...

```

I got the highlighting of words in the single text, from 2 fields having different analyzers.

Documentation

> **[Highlighting | Elasticsearch Guide \[7.14\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#matched-fields)**

---

<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:** [October 3, 2021, 12:54pm UTC](https://discuss.elastic.co/t/highlighting-of-exact-search-with-simple-query-string/283292/3 "2021-10-03T12:54:06Z")

</div>

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