Hi,
I just spent a few hours trying to get highlighting to work. I am using the
Java API and I am trying to highlight the 'artist' field in my documents.
My code looks roughly like this:
searchRequestBuilder.addHighlightedField("artist");
...
SearchResponse response = searchRequestBuilder.execute().actionGet();
...
for (SearchHit hit : response.getHits()) {
T entity = mapper.readValue(hit.getSourceAsString().getBytes(),
entityClass);
}
When I execute the code, the SearchHit.getHighlightFields() contains the
'artist' field as expected (and it's correctly highlighted with the
tags...) However, 'artist' in the JSON returned from getSourceAsString() is
not highlighted. That means that the field is not highlighted in my java
bean and in the gui... I couldn't figure out an easy way to have the fields
in the JSON highlighted as well. I'd appreciate any pointers, I've been
searching the docs for hours
I just spent a few hours trying to get highlighting to work. I am using
the Java API and I am trying to highlight the 'artist' field in my
documents.
My code looks roughly like this:
searchRequestBuilder.addHighlightedField("artist");
...
SearchResponse response = searchRequestBuilder.execute().actionGet();
...
for (SearchHit hit : response.getHits()) {
T entity = mapper.readValue(hit.getSourceAsString().getBytes(),
entityClass);
}
When I execute the code, the SearchHit.getHighlightFields() contains the
'artist' field as expected (and it's correctly highlighted with the
tags...) However, 'artist' in the JSON returned from getSourceAsString() is
not highlighted. That means that the field is not highlighted in my java
bean and in the gui... I couldn't figure out an easy way to have the fields
in the JSON highlighted as well. I'd appreciate any pointers, I've been
searching the docs for hours
The highlighted fields come back in
.highlightFields()/.getHighlightedFields(). If you want the highlighted
values you'll have to read from those rather than the source. When I
search I typically don't ask for the source - maybe just the id and the
highlights. That gives me enough to build the search results without
needing the source.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.