# Elasticsearch exclude bool “term” from getting highlighted

**URL:** <https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258>\
**Category:** Elasticsearch\
**Created:** [August 19, 2013, 5:16pm UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258 "2013-08-19T17:16:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinamar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vinamar](https://discuss.elastic.co/u/vinamar)\
**Post date:** [August 19, 2013, 5:16pm UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258/1 "2013-08-19T17:16:45Z")

</div>

I have the following elastic search query with query string that should  
match all the fields and term query should match the respective fields  
given below. I want only the query\_string to be part of the highlight.  
When i use required\_field\_match it highlights only the term "email" on the  
channel field. without required\_field\_match it matches "email" and  
query\_string on all the fields which i dont want. Can you let me know how  
to exclude "channel" field from highlight ?

```
 {
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "channel":"email"
               }
            },
            {
               "query_string":{
                  "query":"\"payment type\"",
                  "default_operator":"AND"
               }
            }
         ]
      }
   },
   "highlight":{
      "pre_tags":[
         "<span class='highlight'>"
      ],
      "post_tags":[
         "</span>"
      ],
      "require_field_match":false,
      "fields":{
         "requestSummary":{
            "number_of_fragments":0
         },
         "emails.emailBody":{
            "number_of_fragments":0
         },
         "chatTextArray.text":{
            "number_of_fragments":0
         },
         "chatTextArray.name":{
            "number_of_fragments":0
         }
      }
   },
   "facets":{
      "channel":{
         "terms":{
            "field":"channel"
         }
      },
      "siteId":{
         "terms":{
            "field":"siteId"
         }
      },
      "closeDt":{
         "terms":{
            "field":"closeDt"
         }
      },
      "srId":{
         "terms":{
            "field":"srId"
         }
      }
   }
}

```

**Search results:**

{  
"highlight":{  
"emails.emailBody":[  
"helps keep your information safe, visit:  
[http://pages.half.ebay.com/help/policy/privacy.html#toc-02](http://pages.half.ebay.com/help/policy/privacy.html#toc-02)  
In this email"  
],  
"requestSummary":[  
"Change payment type"  
]  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 19, 2013, 6:39pm UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258/2 "2013-08-19T18:39:35Z")

</div>

maybe you can use a filtered query instead like this:

{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query":""payment type"",  
"default\_operator":"AND"  
}  
},  
"filter": {  
"term": {  
"channel": "email"  
}  
}  
}  
}  
}

On Monday, August 19, 2013 7:16:45 PM UTC+2, Vinoth Amar wrote:

> I have the following Elasticsearch query with query string that should  
> match all the fields and term query should match the respective fields  
> given below. I want only the query\_string to be part of the highlight.  
> When i use required\_field\_match it highlights only the term "email" on the  
> channel field. without required\_field\_match it matches "email" and  
> query\_string on all the fields which i dont want. Can you let me know how  
> to exclude "channel" field from highlight ?
> 
> ```
> {
> "query":{
> "bool":{
> "must":[
> {
> "term":{
> "channel":"email"
> }
> },
> {
> "query_string":{
> "query":"\"payment type\"",
> "default_operator":"AND"
> }
> }
> ]
> }
> },
> "highlight":{
> "pre_tags":[
> "<span class='highlight'>"
> ],
> "post_tags":[
> "</span>"
> ],
> "require_field_match":false,
> "fields":{
> "requestSummary":{
> "number_of_fragments":0
> },
> "emails.emailBody":{
> "number_of_fragments":0
> },
> "chatTextArray.text":{
> "number_of_fragments":0
> },
> "chatTextArray.name":{
> "number_of_fragments":0
> }
> }
> },
> "facets":{
> "channel":{
> "terms":{
> "field":"channel"
> }
> },
> "siteId":{
> "terms":{
> "field":"siteId"
> }
> },
> "closeDt":{
> "terms":{
> "field":"closeDt"
> }
> },
> "srId":{
> "terms":{
> "field":"srId"
> }
> }
> }
> }
> 
> ```
> 
> **Search results:**
> 
> {  
> "highlight":{  
> "emails.emailBody":[  
> "helps keep your information safe, visit:  
> [Electronics, Cars, Fashion, Collectibles & More | eBay](http://pages.half.ebay.com/help/policy/privacy.html#toc-02)  
> In this email"  
> ],  
> "requestSummary":[  
> "Change payment type"  
> ]  
> }  
> }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vinamar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vinamar](https://discuss.elastic.co/u/vinamar)\
**Post date:** [August 20, 2013, 5:49pm UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258/3 "2013-08-20T17:49:03Z")

</div>

Thanks Siman it worked !

On Monday, August 19, 2013 11:39:35 AM UTC-7, simonw wrote:

> maybe you can use a filtered query instead like this:
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "query":""payment type"",  
> "default\_operator":"AND"  
> }  
> },  
> "filter": {  
> "term": {  
> "channel": "email"  
> }  
> }  
> }  
> }  
> }
> 
> On Monday, August 19, 2013 7:16:45 PM UTC+2, Vinoth Amar wrote:
> 
> > I have the following Elasticsearch query with query string that should  
> > match all the fields and term query should match the respective fields  
> > given below. I want only the query\_string to be part of the highlight.  
> > When i use required\_field\_match it highlights only the term "email" on the  
> > channel field. without required\_field\_match it matches "email" and  
> > query\_string on all the fields which i dont want. Can you let me know how  
> > to exclude "channel" field from highlight ?
> > 
> > ```
> > {
> > "query":{
> > "bool":{
> > "must":[
> > {
> > "term":{
> > "channel":"email"
> > }
> > },
> > {
> > "query_string":{
> > "query":"\"payment type\"",
> > "default_operator":"AND"
> > }
> > }
> > ]
> > }
> > },
> > "highlight":{
> > "pre_tags":[
> > "<span class='highlight'>"
> > ],
> > "post_tags":[
> > "</span>"
> > ],
> > "require_field_match":false,
> > "fields":{
> > "requestSummary":{
> > "number_of_fragments":0
> > },
> > "emails.emailBody":{
> > "number_of_fragments":0
> > },
> > "chatTextArray.text":{
> > "number_of_fragments":0
> > },
> > "chatTextArray.name":{
> > "number_of_fragments":0
> > }
> > }
> > },
> > "facets":{
> > "channel":{
> > "terms":{
> > "field":"channel"
> > }
> > },
> > "siteId":{
> > "terms":{
> > "field":"siteId"
> > }
> > },
> > "closeDt":{
> > "terms":{
> > "field":"closeDt"
> > }
> > },
> > "srId":{
> > "terms":{
> > "field":"srId"
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > **Search results:**
> > 
> > {  
> > "highlight":{  
> > "emails.emailBody":[  
> > "helps keep your information safe, visit:  
> > [Electronics, Cars, Fashion, Collectibles & More | eBay](http://pages.half.ebay.com/help/policy/privacy.html#toc-02)  
> > In this email"  
> > ],  
> > "requestSummary":[  
> > "Change payment type"  
> > ]  
> > }  
> > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 20, 2013, 7:31pm UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258/4 "2013-08-20T19:31:46Z")

</div>

YW!

On Tuesday, August 20, 2013 7:49:03 PM UTC+2, Vinoth Amar wrote:

> Thanks Siman it worked !
> 
> On Monday, August 19, 2013 11:39:35 AM UTC-7, simonw wrote:
> 
> > maybe you can use a filtered query instead like this:
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "query\_string": {  
> > "query":""payment type"",  
> > "default\_operator":"AND"  
> > }  
> > },  
> > "filter": {  
> > "term": {  
> > "channel": "email"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > On Monday, August 19, 2013 7:16:45 PM UTC+2, Vinoth Amar wrote:
> > 
> > > I have the following Elasticsearch query with query string that should  
> > > match all the fields and term query should match the respective fields  
> > > given below. I want only the query\_string to be part of the highlight.  
> > > When i use required\_field\_match it highlights only the term "email" on the  
> > > channel field. without required\_field\_match it matches "email" and  
> > > query\_string on all the fields which i dont want. Can you let me know how  
> > > to exclude "channel" field from highlight ?
> > > 
> > > ```
> > > {
> > > "query":{
> > > "bool":{
> > > "must":[
> > > {
> > > "term":{
> > > "channel":"email"
> > > }
> > > },
> > > {
> > > "query_string":{
> > > "query":"\"payment type\"",
> > > "default_operator":"AND"
> > > }
> > > }
> > > ]
> > > }
> > > },
> > > "highlight":{
> > > "pre_tags":[
> > > "<span class='highlight'>"
> > > ],
> > > "post_tags":[
> > > "</span>"
> > > ],
> > > "require_field_match":false,
> > > "fields":{
> > > "requestSummary":{
> > > "number_of_fragments":0
> > > },
> > > "emails.emailBody":{
> > > "number_of_fragments":0
> > > },
> > > "chatTextArray.text":{
> > > "number_of_fragments":0
> > > },
> > > "chatTextArray.name":{
> > > "number_of_fragments":0
> > > }
> > > }
> > > },
> > > "facets":{
> > > "channel":{
> > > "terms":{
> > > "field":"channel"
> > > }
> > > },
> > > "siteId":{
> > > "terms":{
> > > "field":"siteId"
> > > }
> > > },
> > > "closeDt":{
> > > "terms":{
> > > "field":"closeDt"
> > > }
> > > },
> > > "srId":{
> > > "terms":{
> > > "field":"srId"
> > > }
> > > }
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > **Search results:**
> > > 
> > > {  
> > > "highlight":{  
> > > "emails.emailBody":[  
> > > "helps keep your information safe, visit:  
> > > [Electronics, Cars, Fashion, Collectibles & More | eBay](http://pages.half.ebay.com/help/policy/privacy.html#toc-02)  
> > > In this email"  
> > > ],  
> > > "requestSummary":[  
> > > "Change payment type"  
> > > ]  
> > > }  
> > > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:20am UTC](https://discuss.elastic.co/t/elasticsearch-exclude-bool-term-from-getting-highlighted/13258/5 "2017-07-06T02:20:26Z")

</div>


