Highlighting of exact search with simple_query_string

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.

"text_html": {"number_of_fragments": 0}

How to correct it ? Thanks.

Configuration:

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

And my query:

{
  "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"}
        }
      ]
    }
  }
}

I got a solution, in the query I added force_source: true

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

{
    "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:

{
  "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

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