Highlight with Bool + filter Query

Hi,

I am having the exact same issue mentioned here: Elasticsearch exclude bool “term” from getting highlighted

Except now, the Filtered Query is deprecated to using Bool Query and with Bool + Filter Query, this is still a problem. I would like to exclude fields from highlight that are "terms" filter and only highlight fields that match my "query_string" Filter. Is this possible?

Hey,
Maybe use a highlight query?

Hi Cristiana,

That actually did work (in a weird way if I may). Basically what I had to do was

{
"from" : 0,
"size" : 10,
"query" : {
"bool" : {
"filter" : [ {
"terms" : {
"someId" : [ "52302" ]
}
}, {
"terms" : {
"someType" : [ "customer" ]
}
}, {
"simple_query_string" : {
"query" : "Suspendisse"
}
} ]
}
},
"_source" : {
"includes" : [ "id", "someId", "someType", "someCategory" ],
"excludes" : [ ]
},
"highlight" : {
"require_field_match" : false,
"highlight_query" : {
"simple_query_string" : {
"query" : "Suspendisse"
}
},
"fields" : {
"*" : { }
}
}
}

I have to put the exact same query_string query in highlight_query and that seemed to work. My question would be, does this impact performance in any way? I am not sure how highlight_query works internally? Does it make another query based off of the query that was given to it ? Because if this adds an extra query to the call, and is indeed not as performant, the type-ahead search with highlight will be slow.

Thoughts?

1 Like

I am currently using this method because I had has_child query and I couldn't use highlighting without highlight_query and my performance didn't change
But, I don't have an exact response, so, my advice is to make some performance tests and/or wait for an opinion?