Reputation: 3
When I use the following query using CURL I successfully get highlights:
{
"query": {
"query_string": {
"query": "Angular"
}
},
"highlight": {
"fields": {
"*": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
]
}
}
}
}
But when I use the following StringQuery in Java, it returns no highlights.
@GetMapping("/search")
public void searchResume(@RequestParam(name = "search") String query) {
Query stringQuery = new StringQuery("""
{
"query_string": {
"query": "$QUERY"
}
}
"highlight": {
"fields": {
"*": {
"pre_tags": ["<mark>"],
"post_tags": ["</mark>"]
}
}
}
""".replace("$QUERY", query));
var result = operations.search(stringQuery, Resume.class);
result.getSearchHits().forEach(sh -> System.out.println(sh.getHighlightFields()));
Does someone know how to get highlighting using the StringQuery api?
Upvotes: 0
Views: 19