I am new to Elasticsearch. I am able to run the following query in Windows prompt:
{
"query": {
"filtered": {
"query": {
"term": {
"title": "crime"
}
},
"filter": {
"term": {
"year": 1961
}
}
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
In Java client, I am able to create the following string and set it in Java client:
{
"filtered": {
"query": {
"term": {
"title": "crime"
}
},
"filter": {
"term": {
"year": 1961
}
}
}
}
SearchResponse sr = client.prepareSearch("book")
.setTypes("history")
.addHighlightedField("title")
.setQuery(the_above_query_string)
However, as show in the above Java code, I have to add highlighted fields via .addHighlightedField("title")
. Can I set the highlight fields via the following string in the above Java code (the way to set query)?
{
"highlight": {
"fields": {
"title": {}
}
}
}