private static Map<String, Object> getMap(GetResponse response) { Map<String, Object> map = null; if (response.isExists() && (map = response.getSourceAsMap()) != null) { map.put("$type", response.getType()); } return map; }
@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.getType(), _settings); } else { log.error("Cannot parse settings for "+singleGetResponse.getType()); } } else { //does not exist or empty source callback.noData(singleGetResponse.getType()); } } else { //failure callback.singleFailure(singleResponse==null?null:singleResponse.getFailure()); } } }
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 type = singleGetResponse.getType(); final long version = singleGetResponse.getVersion(); if (ref == null || ref.length() == 0) {
/** * The type of the document. */ public String getType() { if (failure != null) { return failure.getType(); } return response.getType(); }
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; }
/** * Get the type name of a document or null if the document does not exist. * This is a replacement of the exist() method which does exactly the same as exist() * but is able to return the type name in case that exist is successful. * Please read the comment to exist() for details. * @param indexName * the name of the index * @param id * the unique identifier of a document * @return the type name of the document if it exists, null otherwise */ public String getType(String indexName, final String id) { GetResponse getResponse = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); return getResponse.isExists() ? getResponse.getType() : null; }
/** * 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 + "]"); } } }
/** * The type of the document. */ public String getScriptLang() { return getResponse.getType(); }
@Override public String getType() { return this.getResponse.getType(); }
/** * The type of the document. */ public String getType() { if (failure != null) { return failure.getType(); } return response.getType(); }
/** * The type of the document. */ public String getType() { if (failure != null) { return failure.getType(); } return response.getType(); }
/** * The type of the document. */ public String getType() { if (failure != null) { return failure.getType(); } return response.getType(); }
/** * The type of the document. */ public String getType() { if (failure != null) { return failure.getType(); } return response.getType(); }
@Override public void onResponse(GetResponse getResponse) { JsonObject source = (getResponse.isExists() ? new JsonObject(getResponse.getSourceAsString()) : null); JsonObject reply = new JsonObject() .put(CONST_INDEX, getResponse.getIndex()) .put(CONST_TYPE, getResponse.getType()) .put(CONST_ID, getResponse.getId()) .put(CONST_VERSION, getResponse.getVersion()) .put(CONST_SOURCE, source); resultHandler.handle(Future.succeededFuture(reply)); }
public static void assertExists(GetResponse response) { String message = String.format(Locale.ROOT, "Expected %s/%s/%s to exist, but does not", response.getIndex(), response.getType(), response.getId()); assertThat(message, response.isExists(), is(true)); }
@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; } }
@SuppressWarnings("unchecked") protected <T extends ESEntity> T buildEntityFromGetResponse(Class<T> entityClass, MultiGetItemResponse item) { GetResponse response = item.getResponse(); if (!response.isExists()) throw new DaoException(String.format( "Entity %s does not exist in %s/%s", response.getId(), response.getIndex(), response.getType())); if (entityClass == null) throw new IllegalArgumentException("Provided Entity class is null"); else if (entityClass.equals(ESNode.class)) return (T) ESNode.Builder.buildFromGetReponse(response); else if (entityClass.equals(ESWay.class)) return (T) ESWay.Builder.buildFromGetReponse(response); else throw new IllegalArgumentException(entityClass.getSimpleName() + " is not a known Entity"); }
private ElasticSearchDoc parse(final GetResponse response) { ElasticSearchDoc result = null; if (response.isExists()) { final Map<String, Object> responseMap = response.getSourceAsMap(); final String user = (String) responseMap.get(ElasticSearchDoc.Field.USER); final boolean deleted = (boolean) responseMap.get(ElasticSearchDoc.Field.DELETED); final long timestamp = (long) responseMap.get(ElasticSearchDoc.Field.TIMESTAMP); @SuppressWarnings("unchecked") final Object dto = metacatJson.parseJsonValue( response.getSourceAsBytes(), getClass(response.getType()) ); result = new ElasticSearchDoc(response.getId(), dto, user, deleted, timestamp); } return result; }