Plain Highlighter logical failure

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

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 :

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

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.

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