Highlight query behaviour in elastic search

Hi ,
My data is stored in below kind of json in elastic search
{ "number" : "0", "journal" : [ { "no" : "1", "createdby" : "sanction", "typeofcomment" : "Normal", "comment" : "einstein", "type" : "Restricted Information", "createdon" : "2021-03-12" }, { "no" : "2", "createdby" : " sanction", "typeofcomment" : "Normal", "comment" : "albert einstein", "type" : "MANAGEMENTSUMMARY", "createdon" : "2021-03-12" } ] }
is it possible to control highlight behavior?, it means if journal.type equals Restricted Information, I don't wanted to get highlight from journal.comment field

Welcome!

I don't think you can do what you described.
But some few things you could think about:

  • Solve that problem in the application layer. For each hit, check if "type" = "Restricted Information" and remove the highlight part from that list
  • If you don't want someone to access this Restricted Information, you could may be use the security layer of Elasticsearch and the field level security (Field level security | Elasticsearch Reference [7.11] | Elastic). This requires a platinum license (or a trial).

@dadoonet
Thanks for suggestion but I feel it is hard to find out which highlight fragment belongs to that specific restricted information type.

I see. You are using an array of nested documents here, right?

Can't you use something like:

{
  "number": "0",
  "journal": [
    {
      "no": "1",
      "createdby": "sanction",
      "typeofcomment": "Normal",
      "comment": "einstein",
      "type": "Restricted Information",
      "createdon": "2021-03-12"
    },
    {
      "no": "2",
      "createdby": " sanction",
      "typeofcomment": "Normal",
      "restricted_comment": "albert einstein",
      "type": "MANAGEMENTSUMMARY",
      "createdon": "2021-03-12"
    }
  ]
}

In which case you know when the content could be restricted or not?