# Highlight\_query does treat all clauses and terms as boolean OR

**URL:** <https://discuss.elastic.co/t/highlight-query-does-treat-all-clauses-and-terms-as-boolean-or/76267>\
**Category:** Elasticsearch\
**Created:** [February 23, 2017, 4:50pm UTC](https://discuss.elastic.co/t/highlight-query-does-treat-all-clauses-and-terms-as-boolean-or/76267 "2017-02-23T16:50:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ps23](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@ps23](https://discuss.elastic.co/u/ps23)\
**Post date:** [February 23, 2017, 4:50pm UTC](https://discuss.elastic.co/t/highlight-query-does-treat-all-clauses-and-terms-as-boolean-or/76267/1 "2017-02-23T16:50:15Z")

</div>

see [https://github.com/elastic/elasticsearch/issues/20676](https://github.com/elastic/elasticsearch/issues/20676)

I have the same issue. The documentation says:  
"It is also possible to highlight against a query other than the search query by setting highlight\_query. This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. Elasticsearch does not validate that highlight\_query contains the search query in any way so it is possible to define it so legitimate query results aren’t highlighted at all. Generally it is better to include the search query in the highlight\_query. Here is an example of including both the search query and the rescore query in highlight\_query."

[https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-highlighting.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-highlighting.html)

It also gives the following example:

```auto
"highlight" : {
        "order" : "score",
        "fields" : {
            "content" : {
                "fragment_size" : 150,
                "number_of_fragments" : 3,
                "highlight_query": {
                    "bool": {
                        "must": {
                            "match": {
                                "content": {
                                    "query": "foo bar"
                                }
                            }
                        },
                        "should": {
                            "match_phrase": {
                                "content": {
                                    "query": "foo bar",
                                    "slop": 1,
                                    "boost": 10.0
                                }
                            }
                        },
                        "minimum_should_match": 0
                    }
                }
            }
        }
    }

```

The currently behaviour treats all terms as OR and highlights anything that it finds no matter if it was defined through bool must, should, query\_string AND, |(value1 + value2).

What is the purpose of having a separate query in the first place then when all that the highlighter does is to extract all terms as a list of terms to match? Is there a way to use boolean logic on the highlighter?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 27, 2017, 8:54am UTC](https://discuss.elastic.co/t/highlight-query-does-treat-all-clauses-and-terms-as-boolean-or/76267/2 "2017-02-27T08:54:58Z")

</div>

Hey,

you configured the `match` query to be an OR query - so this is expected behaviour (you can change this of course in the match query). As mentioned in the documentation, a highlight query makes sense, when you use a fast query to get matching documents and a slower query to refine the results by using the `rescore` query. Then using that slower query in the `highlight_query` makes a lot of sense.

hope that helps!

--Alex

---

<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:** [March 27, 2017, 8:55am UTC](https://discuss.elastic.co/t/highlight-query-does-treat-all-clauses-and-terms-as-boolean-or/76267/3 "2017-03-27T08:55:04Z")

</div>

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