public SearchResult(SearchResponse resp) { SearchHits hits = resp.getHits(); this.total = hits.getTotalHits(); results = new ArrayList<>(hits.getHits().length); for (SearchHit searchHit : hits.getHits()) { if (searchHit.getSourceAsMap() != null) { results.add(searchHit.getSourceAsMap()); } else if (searchHit.getFields() != null) { Map<String, DocumentField> fields = searchHit.getFields(); results.add(toFieldsMap(fields)); } } }
protected SearchHit createUnmachedResult( List<Field> secondTableReturnedFields, int docId, String t1Alias, String t2Alias, SearchHit hit) { String unmatchedId = hit.getId() + "|0"; Text unamatchedType = new Text(hit.getType() + "|null"); SearchHit searchHit = new SearchHit(docId, unmatchedId, unamatchedType, hit.getFields()); searchHit.sourceRef(hit.getSourceRef()); searchHit.getSourceAsMap().clear(); searchHit.getSourceAsMap().putAll(hit.getSourceAsMap()); Map<String,Object> emptySecondTableHitSource = createNullsSource(secondTableReturnedFields); mergeSourceAndAddAliases(emptySecondTableHitSource, searchHit,t1Alias,t2Alias); return searchHit; }
private List<EventExecution> mapEventExecutionsResponse(SearchResponse response) throws IOException { SearchHit[] hits = response.getHits().getHits(); List<EventExecution> executions = new ArrayList<>(hits.length); for (SearchHit hit : hits) { String source = hit.getSourceAsString(); EventExecution tel = objectMapper.readValue(source, EventExecution.class); executions.add(tel); } return executions; }
public ComponentHit(SearchHit hit) { this.uuid = hit.getId(); this.highlightedText = getHighlightedText(hit); }
public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter, TimeZone timeZone) { this.facets = new Facets(response, timeZone); this.total = response.getHits().getTotalHits(); this.docs = EsUtils.convertToDocs(response.getHits(), converter); }
public static CandidateResult parseIndexDocId( final SearchHit hit, boolean hasGeoSortPredicates ) { final String documentId = hit.getId(); // geosort predicates always added as the first sort in the ES filter, and the distance is represented as the // corresponding sortValue in the searchHit. // see org.apache.usergrid.persistence.index.impl.SearchRequestBuilderStrategy.applySortPredicates() final double distance = hasGeoSortPredicates ? (double) hit.sortValues()[0] : -1; return parseIndexDocId(documentId,distance); }
protected void mergeSourceAndAddAliases(Map<String,Object> secondTableHitSource, SearchHit searchHit,String t1Alias,String t2Alias) { Map<String,Object> results = mapWithAliases(searchHit.getSourceAsMap(), t1Alias); results.putAll(mapWithAliases(secondTableHitSource, t2Alias)); searchHit.getSourceAsMap().clear(); searchHit.getSourceAsMap().putAll(results); }
public void run() throws IOException, SqlParseException { long timeBefore = System.currentTimeMillis(); List<SearchHit> combinedSearchHits = innerRun(); int resultsSize = combinedSearchHits.size(); SearchHit[] hits = combinedSearchHits.toArray(new SearchHit[resultsSize]); this.results = new SearchHits(hits, resultsSize,1.0f); long joinTimeInMilli = System.currentTimeMillis() - timeBefore; this.metaResults.setTookImMilli(joinTimeInMilli); }
@Override public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { List<String> result = new ArrayList<String>(); for (SearchHit searchHit : response.getHits().getHits()) { String id = searchHit.getId(); result.add(id); } if (result.size() > 0) { return new AggregatedPageImpl<T>((List<T>) result, response.getScrollId()); } return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId()); } };
private List<EventExecution> mapEventExecutionsResponse(SearchResponse response) throws IOException { SearchHit[] hits = response.getHits().getHits(); List<EventExecution> executions = new ArrayList<>(hits.length); for (SearchHit hit : hits) { String source = hit.getSourceAsString(); EventExecution tel = objectMapper.readValue(source, EventExecution.class); executions.add(tel); } return executions; } }
private IdScrollIterator(EsClient esClient, SearchResponse scrollResponse, Function<String, I> idConverter) { this.esClient = esClient; this.scrollId = scrollResponse.getScrollId(); this.idConverter = idConverter; Collections.addAll(hits, scrollResponse.getHits().getHits()); }
public static CandidateResult parseIndexDocId( final SearchHit hit ) { return parseIndexDocId(hit.getId()); }
public SearchIdResult(SearchResponse response, Function<String, ID> converter, TimeZone timeZone) { this.facets = new Facets(response, timeZone); this.total = response.getHits().getTotalHits(); this.ids = convertToIds(response.getHits(), converter); }
public static Object getFieldValue(SearchHit hit,String field){ return deepSearchInMap(hit.getSourceAsMap(),field); }
private void extractFromSource(SearchHit hit) { Map<String, Object> map = hit.getSourceAsMap(); for (Map.Entry<String, Object> entry : map.entrySet()) { String jsonPath = entry.getKey(); Object entryValue = entry.getValue(); setFieldIfExists(jsonPath, entryValue); } } }
private Object getFieldValue(SearchHit hit, String fieldName) { Map<String,Object> sourceAsMap = hit.getSourceAsMap(); if(fieldName.contains(".")){ String[] split = fieldName.split("\\."); return Util.searchPathInMap(sourceAsMap, split); } else if(sourceAsMap.containsKey(fieldName)){ return sourceAsMap.get(fieldName); } return null; }