Highlight exact phrases/keywords

hello everyone
I want to highlight the query match but to be an exact match when words or phrases

{
  "body": {
    "highlight": {
      "fields": {
        "textContent": {
          "fragment_size": 150,
          "number_of_fragments": 10
        }
      },
      "fragmenter": "span",
      "post_tags": [
        "</em>"
      ],
      "pre_tags": [
        "<em class='highlight' >"
      ],
      "tags_schema": "styled"
    },
    "query": {
      "bool": {
        "filter": {
          "term": {
            "_id": "_uj-vugO/LKIC_CP_9_190607_50_TD.pdf-1643724161041914"
          }
        },
        "must": {
          "query_string": {
            "fields": [
              "textContent",
              "title"
            ],
            "query": "fire \"ground floor\" \"implementation plan\""
          }
        }
      }
    }
  },
  "filterPath": "hits",
  "index": "my-index"
}

this is the search term: fire "ground floor" "implementation plan"
this is what I want"

  • "ground floor" phrase highlighted
  • "fire" word highlighted
  • "implementation plan" ignored because the phrase doesn't exist

LEVEL LIGHTING & DRY FIRE LAYOUT
180484-JHA-SKE-E106 - LEVEL 1 LIGHTING & DRY FIRE LAYOUT
180484-JHA-SKE-E107 - ROOF LIGHTING & DRY FIRE LAYOUT
180484-FLOOR SLAB PLAN
S182476-S06.02-2 GROUND FLOOR WALKWAY SLAB PLAN

but this is what I'm getting

  • fire highlighted (this is ok)
  • floor highlighted ( this is not ok since it is alone and not in the phrase)
  • plan highlighted ( this is not ok since the phrase with "implementation plan" don't match)

LEVEL LIGHTING & DRY FIRE LAYOUT
180484-JHA-SKE-E106 - LEVEL 1 LIGHTING & DRY FIRE LAYOUT
180484-JHA-SKE-E107 - ROOF LIGHTING & DRY FIRE LAYOUT
180484-FLOOR SLAB PLAN
S182476-S06.02-2 GROUND FLOOR WALKWAY SLAB PLAN

thanks in advance

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