i am using elasticsearch bool querry with springboot application my querry is as follow:
public List<feed> search(String id) throws IOException {
Query bodyTermQuery = TermQuery.of(tq -> tq.field("body").value(id))._toQuery();
Query titleTermQuery = TermQuery.of(tq -> tq.field("title").value(id))._toQuery();
Query matchQuery = MatchQuery.of(mq -> mq.field("comment.c_text").query(id))._toQuery();
Query nestedQuery = NestedQuery.of(nq -> nq.path("comment").query(matchQuery)
.innerHits(ih -> ih.highlight(h -> h.requireFieldMatch(true))))._toQuery();
SearchResponse<feed> searchResponse = elasticsearchClient.search(
s -> s.index("feeds").query(q -> q.bool(b -> b.should(nestedQuery, titleTermQuery, bodyTermQuery))),
feed.class);
List<Hit<feed>> hits = searchResponse.hits().hits();
List<feed> feeds = new ArrayList<>();
feed f=null;
for(Hit object : hits){
f = (feed) object.source();
System.out.println("Feed : "+ f.getComment().get(1).getC_text());
feeds.add(f); }
return feeds;
}
i dont why it is not working in my springboot application i have used kibana to get my desired output and working fine but in my springboot application it didnt give my out the querry i used on kibana is as follow :
GET feeds/_search
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "comment",
"query": {
"match": {
"comment.c_text": "hey"
}
},"inner_hits": {
"highlight": {
"require_field_match": "true"
}
}
}
},
{
"term": {
"title": {
"value": "hey"
}
}
},
{
"term": {
"body": {
"value": "hey"
}
}
}
]
}
}
}
detail error
023-01-02 13:08:12.792[0;39m [31mERROR[0;39m [35m5008[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'Highlight.fields'] with root cause
Can Anyone help me learn more about highlights.fields how can i study it how can i use it because i want to mapp the inner hits in my response