Highlight with Bool + filter Query


(Shivang Shah) #1

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?


(Cristiana Tiugan) #2

Hey,
Maybe use a highlight query?
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_highlight_query


(Shivang Shah) #3

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?


(Cristiana Tiugan) #4

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?


(system) #5