public Set<String> existBulk(String indexName, String typeName, final Collection<String> ids) { if (ids == null || ids.size() == 0) return new HashSet<>(); MultiGetResponse multiGetItemResponses = elasticsearchClient.prepareMultiGet() .add(indexName, typeName, ids) .get(); Set<String> er = new HashSet<>(); for (MultiGetItemResponse itemResponse : multiGetItemResponses) { GetResponse response = itemResponse.getResponse(); if (response.isExists()) { er.add(response.getId()); } } return er; }
@Override public void onResponse(MultiGetResponse response) { MultiGetItemResponse[] responses = response.getResponses(); for (int i = 0; i < responses.length; i++) { MultiGetItemResponse singleResponse = responses[i]; if(singleResponse != null && !singleResponse.isFailed()) { GetResponse singleGetResponse = singleResponse.getResponse(); if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) { //success final Tuple<Long, Settings> _settings = toSettings(singleGetResponse); if(_settings.v2() != null) { callback.success(singleGetResponse.getId(), _settings); } else { log.error("Cannot parse settings for "+singleGetResponse.getId()); } } else { //does not exist or empty source callback.noData(singleGetResponse.getId()); } } else { //failure callback.singleFailure(singleResponse==null?null:singleResponse.getFailure()); } } }
@Override public <T> T mapResult(GetResponse response, Class<T> clazz) { T result = mapEntity(response.getSourceAsString(), clazz); if (result != null) { setPersistentEntityId(result, response.getId(), clazz); setPersistentEntityVersion(result, response.getVersion(), clazz); } return result; }
@Override public <T> LinkedList<T> mapResults(MultiGetResponse responses, Class<T> clazz) { LinkedList<T> list = new LinkedList<>(); for (MultiGetItemResponse response : responses.getResponses()) { if (!response.isFailed() && response.getResponse().isExists()) { T result = mapEntity(response.getResponse().getSourceAsString(), clazz); setPersistentEntityId(result, response.getResponse().getId(), clazz); setPersistentEntityVersion(result, response.getResponse().getVersion(), clazz); list.add(result); } } return list; }
private static GetResult getResponseToGetResult(GetResponse response) { return new GetResult(response.getIndex(), response.getType(), response.getId(), response.getVersion(), response.isExists(), response.getSourceAsBytesRef(), response.getFields()); }
private Tuple<Long, Settings> toSettings(GetResponse singleGetResponse) { final BytesReference ref = singleGetResponse.getSourceAsBytesRef(); final String id = singleGetResponse.getId(); final long version = singleGetResponse.getVersion();
/** * The id of the document. */ public String getId() { if (failure != null) { return failure.getId(); } return response.getId(); }
protected static Map<String, Object> getMap(GetResponse response) { Map<String, Object> map = null; if (response.isExists() && (map = response.getSourceAsMap()) != null) { if (!map.containsKey("id")) map.put("id", response.getId()); if (!map.containsKey("type")) map.put("type", response.getType()); } return map; }
Assert.assertEquals(response.getId(), id1, "Response id matches request"); System.out.println(malformedDocPolicy + ":" + response.toString()); if (response.isExists()) { Assert.assertEquals(response.getId(), id2, "Response id matches request"); System.out.println(malformedDocPolicy + ":" + response.toString()); if (response.isExists()) {
Assert.assertEquals(response.getId(), id, "Response id matches request"); Assert.assertEquals(response.isExists(), true, "Document not found"); } catch (Exception e) {
public Set<String> existBulk(String indexName, String typeName, final Collection<String> ids) { if (ids == null || ids.size() == 0) return new HashSet<>(); MultiGetResponse multiGetItemResponses = elasticsearchClient.prepareMultiGet() .add(indexName, typeName, ids) .get(); Set<String> er = new HashSet<>(); for (MultiGetItemResponse itemResponse : multiGetItemResponses) { GetResponse response = itemResponse.getResponse(); if (response.isExists()) { er.add(response.getId()); } } return er; }
@Override public Record findRecordById(String id) { GetResponse getResponse = client .prepareGet(this.indexName, this.indexType, id).execute() .actionGet(); return this .readFromSource(getResponse.getId(), getResponse.getSource()); }
/** * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster. */ void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException { if (false == response.isExists()) { listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId())); return; } if (response.isSourceEmpty()) { listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId())); return; } try (XContentParser parser = XContentHelper .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) { TaskResult result = TaskResult.PARSER.apply(parser, null); listener.onResponse(new GetTaskResponse(result)); } } }
/** * Checks if the requested document or source is missing. * * @param response a response * @throws ResourceNotFoundException if the document or source is missing */ private void checkResource(final GetResponse response) { final String index = response.getIndex(); final String type = response.getType(); final String id = response.getId(); if (response.isExists() == false) { throw new ResourceNotFoundException("Document not found [" + index + "]/[" + type + "]/[" + id + "]"); } else if (response.isSourceEmpty()) { throw new ResourceNotFoundException("Source not found [" + index + "]/[" + type + "]/[" + id + "]"); } } }
@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, 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; }
@SuppressWarnings("unchecked") public static ESNode buildFromGetReponse(GetResponse response) { if (!response.getType().equals(ESEntityType.NODE.getIndiceName())) throw new IllegalArgumentException("Provided GetResponse is not a Node"); Builder builder = new Builder(); builder.id = Long.valueOf(response.getId()); builder.tags = (Map<String, String>) response.getSource().get("tags"); Map<String, Object> shape = (Map<String, Object>) response.getSource().get("shape"); List<Double> location = (List<Double>) shape.get("coordinates"); builder.latitude = location.get(1); builder.longitude = location.get(0); return builder.build(); }
private Edge createEdge(GetResponse hit) { Map<String, Object> fields = hit.getSource(); BaseVertex outVertex = graph.getQueryHandler().vertex(fields.get(DocEdge.OutId), fields.get(DocEdge.OutLabel).toString(), null, Direction.OUT); BaseVertex inVertex = graph.getQueryHandler().vertex(fields.get(DocEdge.InId), fields.get(DocEdge.InLabel).toString(), null, Direction.IN); BaseEdge edge = new DocEdge(hit.getId(), hit.getType(), null, outVertex, inVertex, graph, elasticMutations, indexName); fields.entrySet().forEach((field) -> edge.addPropertyLocal(field.getKey(), field.getValue())); return edge; } }
public ElasticsearchSample get(Object key) { GetResponse getResponse = client.prepareGet(index, type, String.valueOf(key)).execute().actionGet(); Map<String, Object> map = getResponse.getSource(); if (map == null) { return null; } else { map.put(ID, getResponse.getId()); return new ElasticsearchSample(this, map); } }