SearchResult extends JestResult { public <T> List<Hit<T, Void>> getHits(Class<T> sourceType) { return getHits(sourceType, true); } SearchResult(SearchResult searchResult);  SearchResult(Gson gson); @Override @Deprecated T getSourceAsObject(Class<T> clazz); @Override @Deprecated List<T> getSourceAsObjectList(Class<T> type); Hit<T, Void> getFirstHit(Class<T> sourceType); Hit<T, K> getFirstHit(Class<T> sourceType, Class<K> explanationType); List<Hit<T, Void>> getHits(Class<T> sourceType); List<Hit<T, Void>> getHits(Class<T> sourceType, boolean addEsMetadataFields); List<Hit<T, K>> getHits(Class<T> sourceType, Class<K> explanationType); List<Hit<T, K>> getHits(Class<T> sourceType, Class<K> explanationType, boolean addEsMetadataFields); Long getTotal(); Float getMaxScore(); MetricAggregation getAggregations(); static final String EXPLANATION_KEY; static final String HIGHLIGHT_KEY; static final String SORT_KEY; static final String[] PATH_TO_TOTAL; static final String[] PATH_TO_MAX_SCORE; }
@Test public void testGetHits() { SearchResult searchResult = new SearchResult(new Gson()); searchResult.setSucceeded(true); searchResult.setJsonString(json); searchResult.setJsonObject(new JsonParser().parse(json).getAsJsonObject()); searchResult.setPathToResult("hits/hits/_source"); List hits = searchResult.getHits(Object.class); assertNotNull(hits); assertFalse("should have 1 hit", hits.isEmpty()); hits = searchResult.getHits(Object.class, Object.class); assertNotNull(hits); assertFalse("should have 1 hit", hits.isEmpty()); }
@Test public void testGetHitsWithoutMetadata() { final SearchResult searchResult = new SearchResult(new Gson()); searchResult.setSucceeded(true); searchResult.setJsonString(json); searchResult.setJsonObject(new JsonParser().parse(json).getAsJsonObject()); searchResult.setPathToResult("hits/hits/_source"); assertTrue(getFirstHitSource(searchResult.getHits(Object.class)).containsKey(SearchResult.ES_METADATA_ID)); assertFalse(getFirstHitSource(searchResult.getHits(Object.class, false)).containsKey(SearchResult.ES_METADATA_ID)); assertTrue(getFirstHitSource(searchResult.getHits(Object.class, Object.class)).containsKey(SearchResult.ES_METADATA_ID)); assertFalse(getFirstHitSource(searchResult.getHits(Object.class, Object.class, false)).containsKey(SearchResult.ES_METADATA_ID)); }
@Test public void testGetHitsWhenOperationFails() { SearchResult searchResult = new SearchResult(new Gson()); searchResult.setSucceeded(false); List hits = searchResult.getHits(Object.class); assertNotNull(hits); assertTrue(hits.isEmpty()); hits = searchResult.getHits(Object.class, Object.class); assertNotNull(hits); assertTrue(hits.isEmpty()); }