# Plain Highlighter logical failure

**URL:** <https://discuss.elastic.co/t/plain-highlighter-logical-failure/81680>\
**Category:** Elasticsearch\
**Created:** [April 8, 2017, 3:00pm UTC](https://discuss.elastic.co/t/plain-highlighter-logical-failure/81680 "2017-04-08T15:00:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lausc](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lausc](https://discuss.elastic.co/u/lausc)\
**Post date:** [April 8, 2017, 3:00pm UTC](https://discuss.elastic.co/t/plain-highlighter-logical-failure/81680/1 "2017-04-08T15:00:21Z")

</div>

I encountered a strange logical behavior while using plain highlighter.  
Here is a minimal working example:

```auto
PUT /test
PUT /test/1 
{"message": "m2 m3"}

GET /test/_search
{
    "query": {
        "bool": {
            "should": [
                {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "message": "m1"
                                }
                            },
                            {
                                "term": {
                                    "message": "m2"
                                }
                            }
                        ]
                    }
                },
                {
                    "bool": {
                        "must": [
                            {
                                "match": {
                                    "message": "m3"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "highlight": {
        "fields": {
            "message": {}
        }
    }
}

```

This is the response i get :

```auto
{
    "took": 2,
    "timed_out": false,
    "hits": {
        "total": 1,
        "max_score": 0.25811607,
        "hits": [
            {
                "_index": "toto",
                "_type": "tata",
                "_id": "1",
                "_score": 0.25811607,
                "_source": {
                    "message": "m2 m3"
                },
                "highlight": {
                    "message": [
                        "<em>m2</em> <em>m3</em>"
                    ]
                }
            }
        ]
    }
}

```

Why are there highlights around `m2`?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [April 10, 2017, 10:30am UTC](https://discuss.elastic.co/t/plain-highlighter-logical-failure/81680/2 "2017-04-10T10:30:11Z")

</div>

The ES highlighters do not respect boolean queries. They extract all terms from the query and try to match them all regardless of the parent clause. This is why "m2" is highlighted even though "m1" is not present in the query.

---

<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:** [May 8, 2017, 10:38am UTC](https://discuss.elastic.co/t/plain-highlighter-logical-failure/81680/3 "2017-05-08T10:38:01Z")

</div>

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