public ResultMessage get(String messageId, String index) throws DocumentNotFoundException, IOException { final Get get = new Get.Builder(index, messageId).type(IndexMapping.TYPE_MESSAGE).build(); final DocumentResult result = client.execute(get); if (!result.isSucceeded()) { throw new DocumentNotFoundException(index, messageId); } @SuppressWarnings("unchecked") final Map<String, Object> message = (Map<String, Object>) result.getSourceAsObject(Map.class, false); return ResultMessage.parseFromSource(result.getId(), result.getIndex(), message); }
private static void checkDocumentEquality(Map<String, Object> expectedDataOfDocument, Get request, DocumentResult dataOfDocumentResponse) { @SuppressWarnings("unchecked") final Map<String, Object> dataOfDocument = (Map<String, Object>) dataOfDocumentResponse.getSourceAsObject(Map.class, false); // Workaround because DeepEquals.deepEquals expects the types to be identical final Map<String, Object> actual = new HashMap<>(dataOfDocument); final Map<String, Object> expected = new HashMap<>(expectedDataOfDocument); if (!DeepEquals.deepEquals(actual, expected)) { throw FailureHandler.createFailure("Expected document for index: %s - type: %s - id: %s is %s, but %s was found.", request.getIndex(), request.getType(), request.getId(), GSON.toJson(expectedDataOfDocument), GSON.toJson(dataOfDocument)); } }
public ResultMessage get(String messageId, String index) throws DocumentNotFoundException, IOException { final Get get = new Get.Builder(index, messageId).type(IndexMapping.TYPE_MESSAGE).build(); final DocumentResult result = client.execute(get); if (!result.isSucceeded()) { throw new DocumentNotFoundException(index, messageId); } @SuppressWarnings("unchecked") final Map<String, Object> message = (Map<String, Object>) result.getSourceAsObject(Map.class, false); return ResultMessage.parseFromSource(result.getId(), result.getIndex(), message); }