Query string and highlighting not working as expected

Hello everyone,

I'm trying to highlight a search query. The below query, is expected to highlight only elastic search if apple is in the text ... unfortunately, NO ! The highlight function does not take care about the boolean expression. Am I correct ?

Thank you.

Nicolas.

{
   "query": {
      "filtered": {
         "query": {
            "query_string": {
               "default_field": "message",
               "query": "flexible OR (elasticsearch AND apple)"
            }
         }
      }
   },
   "highlight": {
      "fields": {
         "message": {}
      }
   }
}

I suspect the filter is getting in the way of the terms extraction process. Either use highlight_query to work around it or remove the filtered query from the query.

PS. I edited your query and replaced "`" with "```" to fix the code block. It makes it much easier to read!

I saw your edition. Thank you.

I removed the filter and apply just query with no filter. Unfortunately, I got the same result :frowning:

{
   "query": {
      "query_string": {
         "default_field": "message",
         "query": "flexible OR (elasticsearch AND apple)"
      }
   },
   "highlight": {
      "fields": {
         "message": {}
      }
   }
}

Oh! I see what you mean:

You are right. For the most part it just flattens the booleans. If you were using a bool query you could use named queries to know which queries match. But, yeah, highlighting tends to flatten.

Well, I can not see the advantage to highlight a text without taking into account the boolean request. Do you have one ?

Thank you.
Nicolas.

That is just how they work. Highlighters are messy and tend to make lots of simplifying assumptions.