# Why must, should is not working in highlight part of elasticsearch?

**URL:** <https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224>\
**Category:** Elasticsearch\
**Created:** [June 25, 2019, 4:25am UTC](https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224 "2019-06-25T04:25:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![princesahu04](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/princesahu04/32/47235_2.png) [@princesahu04](https://discuss.elastic.co/u/princesahu04)\
**Post date:** [June 25, 2019, 4:25am UTC](https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224/1 "2019-06-25T04:25:20Z")

</div>

This is my query

```
GET bond_covenant/_search
{
  "_source": false,
  "query": {
    "nested": {
      "path": "doc",
       "query": {
          "nested": {
            "path": "doc.container",
            "query": {
              "nested": {
                "path": "doc.container.sections",
                "query": {
                  "nested": {
                    "path": "doc.container.sections.sentences",
                    "query": {
                      "bool": {
                        "must": [
                         {
                           "match_phrase": {"doc.container.sections.sentences.text": "holding"}
                           
                         },
                         {
                           "match_phrase": {"doc.container.sections.sentences.text": "restricted"}
                           
                         }
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
       }
    }   
  },  
    "highlight": {
       "fragment_size" : 100, 
      "no_match_size": 0, 
        "fields" : {
          "doc.container.sections.sentences.text" : {}
          
          
        }
    } 
}

```

And the output I got is

```
"max_score" : 4.334105,
    "hits" : [
      {
        "_index" : "grtgt",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 4.334105,
        "highlight" : {
          "doc.container.sections.sentences.text" : [
            "<em>Holdings</em> trr hyhy hyjhuyju ggdd <em>Restricted</em> Subsidiaries to, directly or indirectly,",
            "eying or northward offending admitting perfectly my and <em>Holdings</em>",
            "provided, that <em>Holdings</em> main highly feebly add people manner say",
            "extremely. Of incommode supported provision on furnished basis of <em>Holdings</em>"
          ]
        }
      },

```

My Question is why highlight part not giving me ( Restricted AND Holdings) output?  
Why I only got Holding in 2nd, 3rd, 4th output, even restricted and holding are present in my sentences.text more than once?  
Also if restricted and holding only present once than it should not give me 2nd, 3rd, 4th output but why it gave me that?

---

<div class="post-metadata">

**Author:** ![Gerome\_Pangan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerome_pangan/32/49318_2.png) [@Gerome\_Pangan](https://discuss.elastic.co/u/Gerome_Pangan)\
**Post date:** [July 3, 2019, 3:21am UTC](https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224/2 "2019-07-03T03:21:43Z")

</div>

how did you solve this?

---

<div class="post-metadata">

**Author:** ![princesahu04](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/princesahu04/32/47235_2.png) [@princesahu04](https://discuss.elastic.co/u/princesahu04)\
**Post date:** [July 4, 2019, 5:18am UTC](https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224/3 "2019-07-04T05:18:53Z")

</div>

I am still working on this problem. My requirement is to search for a paragraph in text from a large amount of unstructured text data so I am using queries and to highlight that paragraph I am using highlighter here.  
To solve this problem I am changing my index function. Earlier I index 1 document in 1 id but now I am trying to index 1 paragraph as 1 id so in this case, I don't need to use the highlighter and also my boolean logic will work. I hope it's clear

---

<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:** [August 1, 2019, 5:19am UTC](https://discuss.elastic.co/t/why-must-should-is-not-working-in-highlight-part-of-elasticsearch/187224/4 "2019-08-01T05:19:33Z")

</div>

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