# Highlight query behaviour in elastic search

**URL:** <https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961>\
**Category:** Elasticsearch\
**Created:** [March 22, 2021, 9:10am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961 "2021-03-22T09:10:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pushpak](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pushpak](https://discuss.elastic.co/u/Pushpak)\
**Post date:** [March 22, 2021, 9:10am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961/1 "2021-03-22T09:10:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 22, 2021, 9:30am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961/2 "2021-03-22T09:30:34Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/field-level-security.html)). This requires a platinum license (or a trial).

---

<div class="post-metadata">

**Author:** ![Pushpak](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pushpak](https://discuss.elastic.co/u/Pushpak)\
**Post date:** [March 22, 2021, 10:11am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961/3 "2021-03-22T10:11:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 22, 2021, 11:08am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961/4 "2021-03-22T11:08:57Z")

</div>

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

Can't you use something like:

```auto
{
  "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?

---

<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:** [April 19, 2021, 11:08am UTC](https://discuss.elastic.co/t/highlight-query-behaviour-in-elastic-search/267961/5 "2021-04-19T11:08:59Z")

</div>

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