ElasticsearchSearcher { private String getExcerpt(SearchHit hit) { StringBuilder excerptBuilder = new StringBuilder(); for (Map.Entry<String, HighlightField> highlight : hit.getHighlightFields().entrySet()) { for (Text text : highlight.getValue().fragments()) { excerptBuilder.append(text.string()); excerptBuilder.append(" ... "); } } return excerptBuilder.toString(); } ElasticsearchSearcher(Client client); SearchResponse search(String token); List<Result> getResults(SearchResponse response); Faceting getFacets(SearchResponse response); SearchResponse search(String token, Collection<String> filterQueries);  }
@Test public void excerptIsAvailable() throws IOException { Result result = indexAndSearchSingle("content"); assertTrue(result.getExcerpt().contains("Content")); assertFalse(result.getExcerpt().contains("[content]")); }