@Override public GetResponse get(GetRequest getRequest) throws IOException { return highLevelClient.get(getRequest); }
@Override public String get(String workflowInstanceId, String fieldToGet) { GetRequest request = new GetRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId); GetResponse response; try { response = elasticSearchClient.get(request); } catch (IOException e) { logger.error("Unable to get Workflow: {} from ElasticSearch index: {}", workflowInstanceId, indexName, e); return null; } if (response.isExists()){ Map<String, Object> sourceAsMap = response.getSourceAsMap(); if (sourceAsMap.containsKey(fieldToGet)){ return sourceAsMap.get(fieldToGet).toString(); } } logger.debug("Unable to find Workflow: {} in ElasticSearch index: {}.", workflowInstanceId, indexName); return null; }
@Override public Map<String, Object> get(String index, String type, String id) throws IOException { GetRequest get = new GetRequest(index, type, id); GetResponse resp = highLevelClient.get(get, new Header[]{}); return resp.getSource(); }
@Override public <T> T queryForObject(GetQuery query, Class<T> clazz, GetResultMapper mapper) { ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz); GetRequest request = new GetRequest(persistentEntity.getIndexName(), persistentEntity.getIndexType(), query.getId()); GetResponse response; try { response = client.get(request); T entity = mapper.mapResult(response, clazz); return entity; } catch (IOException e) { throw new ElasticsearchException("Error while getting for request: " + request.toString(), e); } }
@Override public ESSearchHit get(String index, String id) throws IOException { GetRequest request = new GetRequest(index, id); GetResponse response = client.get(request, RequestOptions.DEFAULT); ESSearchHit hit = new ESSearchHit(); hit.setIndex(response.getIndex()); hit.setId(response.getId()); hit.setVersion(response.getVersion()); hit.setSourceAsMap(response.getSourceAsMap()); return hit; }
@Override public ESSearchHit get(String index, String id) throws IOException { GetRequest request = new GetRequest(index, getDefaultTypeName(), id); GetResponse response = client.get(request); ESSearchHit hit = new ESSearchHit(); hit.setIndex(response.getIndex()); hit.setId(response.getId()); hit.setVersion(response.getVersion()); hit.setSourceAsMap(response.getSourceAsMap()); return hit; }
@Override public ESSearchHit get(String index, String id) throws IOException { GetRequest request = new GetRequest(index, getDefaultTypeName(), id); GetResponse response = client.get(request, RequestOptions.DEFAULT); ESSearchHit hit = new ESSearchHit(); hit.setIndex(response.getIndex()); hit.setId(response.getId()); hit.setVersion(response.getVersion()); hit.setSourceAsMap(response.getSourceAsMap()); return hit; }
@Override public GetResponse get(GetRequest request) { try { return client.get(request, RequestOptions.DEFAULT); } catch (IOException e) { throw new NuxeoException(e); } }
@Override public Map<String, Object> get(String index, String type, String id) throws IOException { GetRequest get = new GetRequest(index, type, id); GetResponse resp = highLevelClient.get(get, new Header[]{}); return resp.getSource(); }
public GetResponse get(String indexName, String type, String id) throws IOException { try { GetRequest getRequest = new GetRequest( indexName, type, id); GetResponse getResponse = client.get(getRequest); return getResponse; } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return null; }
@Override public GetResponse selectIndex(String index, String type, String id) throws Exception { GetRequest request = new GetRequest(index, type, id); log.debug(request.toString()); return client().get(request); }
private String getLastUpdate() { String res = ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //TODO: status update GetRequest getRequest = new GetRequest(this.statusIndex, "last_update", riverName ); //TODO: move to async ? try { GetResponse getResponse = client.get(getRequest); if(!getResponse.isSourceEmpty()){ Long updated = (Long) getResponse.getSource().get("updated_at"); res = sdf.format(updated); } } catch (IOException e) { logger.error("Could not get last_update, use Date(0)", e); res = sdf.format(new Date(0)); } return res; }
public void run() { if (esClient == null) { try { esClient = ElasticSearchConnection.getClient(stormConf, "config"); } catch (Exception e) { LOG.error("Exception while creating ES connection", e); } } if (esClient != null) { LOG.info("Reloading json resources from ES"); try { GetResponse response = esClient.get(new GetRequest( "config", "config", resource.getResourceFile())); resource.loadJSONResources(new ByteArrayInputStream( response.getSourceAsBytes())); } catch (Exception e) { LOG.error("Can't load config from ES", e.getMessage()); } } } }, 0, refreshRate * 1000);
public void run() { if (esClient == null) { try { esClient = ElasticSearchConnection.getClient(stormConf, "config"); } catch (Exception e) { LOG.error("Exception while creating ES connection", e); } } if (esClient != null) { LOG.info("Reloading json resources from ES"); try { GetResponse response = esClient.get(new GetRequest( "config", "config", resource.getResourceFile())); resource.loadJSONResources(new ByteArrayInputStream( response.getSourceAsBytes())); } catch (Exception e) { LOG.error("Can't load config from ES", e.getMessage()); } } } }, 0, refreshRate * 1000);
private void setClusterStatus(String status) { String statusIndex = indexName + "_status"; boolean indexing = false; GetRequest getRequest = new GetRequest(statusIndex, "last_update" , riverName); try { GetResponse getResponse = client.get(getRequest); if(getResponse.getSource().get("status") == "indexing"){ indexing = true; } } catch (IOException e) { //e.printStackTrace(); } if(!indexing){ Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("status", status); UpdateRequest request = new UpdateRequest( statusIndex, "last_update", riverName) .doc(jsonMap); try { UpdateResponse updateResponse = client.update(request); logger.info("Updating index {} status to: indexing", riverName); } catch (IOException e) { logger.error("{}", e); } } else { } }
/** * Retrieve an indexed Fact by its UUID. Returns NULL if Fact cannot be fetched from ElasticSearch. * * @param id UUID of indexed Fact * @return Indexed Fact or NULL if not available */ public FactDocument getFact(UUID id) { if (id == null) return null; GetResponse response; try { GetRequest request = new GetRequest(INDEX_NAME, TYPE_NAME, id.toString()); response = clientFactory.getHighLevelClient().get(request); } catch (IOException ex) { throw logAndExit(ex, String.format("Could not perform request to fetch Fact with id = %s.", id)); } if (response.isExists()) { LOGGER.info("Successfully fetched Fact with id = %s.", id); return decodeFactDocument(id, response.getSourceAsBytes()); } else { // Fact isn't indexed in ElasticSearch, log warning and return null. LOGGER.warning("Could not fetch Fact with id = %s. Fact not indexed?", id); return null; } }
} else if (operation == ElasticsearchOperation.GetById) { GetRequest getRequest = message.getBody(GetRequest.class); message.setBody(restHighLevelClient.get(getRequest, RequestOptions.DEFAULT)); } else if (operation == ElasticsearchOperation.Bulk) { BulkRequest bulkRequest = message.getBody(BulkRequest.class);
private boolean checkRiverNotExists() { GetRequest getRequest = new GetRequest(indexer.getRIVER_INDEX(), "river", riverName); try { GetResponse getResponse = client.get(getRequest); if (getResponse.isExists()) { return false; } else { logger.error("River doesn't exist anymore"); logger.error("INDEXING CANCELLED"); //TODO: update global-search_status ? or remove indexed cluster? this.close(); return true; } } catch (IOException e) { e.printStackTrace(); logger.error("River doesn't exist anymore"); logger.error("INDEXING CANCELLED"); this.close(); return true; } }
@Override public ESSearchHit get(String index, String type, String id) throws IOException { GetRequest request = new GetRequest(index, type, id); GetResponse response = client.get(request); ESSearchHit hit = new ESSearchHit(); hit.setIndex(response.getIndex()); hit.setId(response.getId()); hit.setVersion(response.getVersion()); hit.setSourceAsMap(response.getSourceAsMap()); return hit; }