Java Code Examples for io.searchbox.core.SearchResult#getHits()
The following examples show how to use
io.searchbox.core.SearchResult#getHits() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EsStorage.java From apiman with Apache License 2.0 | 6 votes |
private void initScroll() throws StorageException { try { Search search = new Search.Builder(query) .addIndex(getIndexName()) .addType(entityType) .setParameter(Parameters.SCROLL, "1m") .addSort(sort) .build(); SearchResult response = esClient.execute(search); if (!response.isSucceeded()) { throw new StorageException("Scrolled query failed " + response.getErrorMessage()); } scrollId = response.getJsonObject().get("_scroll_id").getAsString(); this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
Example 2
Source File: EsStorage.java From apiman with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private void fetch() throws StorageException { try { Builder builder = new SearchScroll.Builder(scrollId, "1m"); SearchScroll scroll = new SearchScroll(builder) { @Override public JestResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { return createNewElasticSearchResult(new SearchResult(gson), responseBody, statusCode, reasonPhrase, gson); } }; SearchResult response = (SearchResult) esClient.execute(scroll); if (!response.isSucceeded()) { throw new StorageException("Scrolled fetch failed " + response.getErrorMessage()); } this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
Example 3
Source File: SearchServiceImpl.java From light-reading-cloud with MIT License | 5 votes |
/** * ES 执行查询结果 * @param query * @return */ private SearchBookResult getSearchResult(String query){ SearchBookResult result = new SearchBookResult(); // 封装查询对象 Search search = new Search.Builder(query) .addIndex(aliasName) .addType(indexType).build(); // 执行查询 try { SearchResult searchResult = this.jestClient.execute(search); List<SearchBookItem> bookList; if (searchResult.isSucceeded()) { // 查询成功,处理结果项 List<SearchResult.Hit<SearchBookItem, Void>> hitList = searchResult.getHits(SearchBookItem.class); bookList = new ArrayList<>(hitList.size()); for (SearchResult.Hit<SearchBookItem, Void> hit : hitList) { bookList.add(hit.source); } } else { bookList = new ArrayList<>(); } // 赋值 result.setTotal(searchResult.getTotal()); result.setBookList(bookList); } catch (IOException e) { LOGGER.error("查询图书异常,查询语句:{}", query, e); } return result; }
Example 4
Source File: JestClient.java From wES with MIT License | 5 votes |
@Override public <T> WSearchResult<T> searchObj(String index, String type, SearchQuery query, Class<T> cls) throws Exception { Search.Builder builder = new Search.Builder(convert.toText(query)); if (index != null) { builder.addIndex(index); } if (type != null) { builder.addType(type); } SearchResult result = _exec(builder.build()); if (result != null) { WSearchResult<T> wresult = new WSearchResult<>(); WSearchResultHits<T> hits = new WSearchResultHits<>(); hits.setTotal(result.getTotal()); List<SearchResult.Hit<T, Void>> allHist = result.getHits(cls); List<WEsDoc<T>> data = new ArrayList<>(); for (SearchResult.Hit<T, Void> hit : allHist) { WEsDoc<T> doc = new WEsDoc<>(); doc.setIndex(hit.index); doc.setType(hit.type); doc.setIndex(hit.index); doc.setSource(hit.source); doc.setScore(hit.score); data.add(doc); } hits.setHits(data); wresult.setHits(hits); return wresult; } return null; }
Example 5
Source File: IndexerResultsMapper.java From eplmp with Eclipse Public License 1.0 | 5 votes |
/** * Map results from elasticsearch to document revisions * * @param searchResult * @param documentSearchQuery * @return */ public List<DocumentRevision> processSearchResult(SearchResult searchResult, DocumentSearchQuery documentSearchQuery) { List<SearchResult.Hit<Map, Void>> hits = searchResult.getHits(Map.class); Set<DocumentIterationKey> documentIterationKeys = new HashSet<>(); if (hits != null) { for (SearchResult.Hit<Map, Void> hit : hits) { Map<?, ?> source = hit.source; documentIterationKeys.add(getDocumentIterationKey(source)); } } LOGGER.log(Level.INFO, "Results: " + documentIterationKeys.size()); return documentIterationKeysToDocumentRevisions(documentSearchQuery.isFetchHeadOnly(), documentIterationKeys); }
Example 6
Source File: IndexerResultsMapper.java From eplmp with Eclipse Public License 1.0 | 5 votes |
/** * Map results from elasticsearch to part revisions * * @param searchResult * @param partSearchQuery * @return */ public List<PartRevision> processSearchResult(SearchResult searchResult, PartSearchQuery partSearchQuery) { List<SearchResult.Hit<Map, Void>> hits = searchResult.getHits(Map.class); Set<PartIterationKey> partIterationKeys = new HashSet<>(); if (hits != null) { for (SearchResult.Hit<Map, Void> hit : hits) { Map<?, ?> source = hit.source; partIterationKeys.add(getPartIterationKey(source)); } } LOGGER.log(Level.INFO, "Results: " + partIterationKeys.size()); return partIterationKeysToPartRevisions(partSearchQuery.isFetchHeadOnly(), partIterationKeys); }
Example 7
Source File: ElasticsearchService.java From c2mon with GNU Lesser General Public License v3.0 | 5 votes |
private List<Object[]> getRawHistory(Long id, Long min, Long max) { String query = String.format("{\n" + " \"size\" : " + maxResults + ",\n" + " \"query\" : {\n" + " \"bool\" : {\n" + " \"must\" : [ {\n" + " \"term\" : {\n" + " \"id\" : %d\n" + " }\n" + " }, {\n" + " \"range\" : {\n" + " \"timestamp\" : {\n" + " \"from\" : %d,\n" + " \"to\" : %d,\n" + " \"include_lower\" : true,\n" + " \"include_upper\" : true\n" + " }\n" + " }\n" + " } ]\n" + " }\n" + " },\n" + " \"sort\" : [ {\n" + " \"timestamp\" : {\n" + " \"order\" : \"asc\"\n" + " }\n" + " } ]\n" + "}", id, min, max); Search search = new Search.Builder(query).addIndex(timeSeriesIndex).build(); try { SearchResult result = client.execute(search); List<Object[]> results = new ArrayList<>(); for (SearchResult.Hit<Map, Void> hit : result.getHits(Map.class)) { results.add(new Object[]{hit.source.get("timestamp"), hit.source.get("value")}); } return results; } catch (IOException e) { throw new RuntimeException("Error querying raw tag history", e); } }
Example 8
Source File: EsStorage.java From apiman with Apache License 2.0 | 5 votes |
/** * Returns a list of entities. * @param type * @param searchSourceBuilder * @throws StorageException */ private List<Hit<Map<String, Object>, Void>> listEntities(String type, SearchSourceBuilder searchSourceBuilder) throws StorageException { try { String query = searchSourceBuilder.string(); Search search = new Search.Builder(query).addIndex(getIndexName()).addType(type).build(); SearchResult response = esClient.execute(search); @SuppressWarnings({ "rawtypes", "unchecked" }) List<Hit<Map<String, Object>, Void>> thehits = (List) response.getHits(Map.class); return thehits; } catch (Exception e) { throw new StorageException(e); } }