@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(); }
/** * Verify the results in an Elasticsearch index. The results must first be produced into the index * using a {@link TestElasticsearchSinkFunction}; * * @param client The client to use to connect to Elasticsearch * @param index The index to check */ public static void verifyProducedSinkData(Client client, String index) { for (int i = 0; i < NUM_ELEMENTS; i++) { GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet(); Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME)); } }
@Override public void execute(Tuple tuple) { try { String index = mapper.getIndex(tuple); String type = mapper.getType(tuple); String id = mapper.getId(tuple); GetResponse response = client.prepareGet(index, type, id).execute() .actionGet(); collector.emit(esOutputDeclarer.getValues(response.getSource())); collector.ack(tuple); } catch (Exception e) { collector.fail(tuple); } }
private SearchGuardLicense createOrGetTrial(String msg) { long created = System.currentTimeMillis(); ThreadContext threadContext = threadPool.getThreadContext(); try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get(); if(get.isExists()) { created = (long) get.getSource().get("val"); } else { try { client.index(new IndexRequest(searchguardIndex) .type("sg") .id("tattr") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .create(true) .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet(); } catch (VersionConflictEngineException e) { //ignore } catch (Exception e) { LOGGER.error("Unable to index tattr", e); } } } return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg); } }
.get(); assertEquals("indexed message id should match", messageId, response.getSource().get("messageId")); assertEquals("indexed id should match", "some-id", response.getSource().get("id")); assertEquals("indexed status should match", EventExecution.Status.COMPLETED.name(), response.getSource().get("status")); });
@Override public Record findRecordById(String id) { GetResponse getResponse = client .prepareGet(this.indexName, this.indexType, id).execute() .actionGet(); return this .readFromSource(getResponse.getId(), getResponse.getSource()); }
Map<String, Object> results = get.getSource();
@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(); }
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); } }
private String getLastUpdatedTimestamp() { GetResponse lastUpdatedTimestampResponse = client.prepareGet().setIndex(riverIndexName).setType(riverName.name()).setId("lastUpdatedTimestamp").execute().actionGet(); if (lastUpdatedTimestampResponse.isExists() && lastUpdatedTimestampResponse.getSource().containsKey("lastUpdatedTimestamp")) { return lastUpdatedTimestampResponse.getSource().get("lastUpdatedTimestamp").toString(); } return null; } }
@Override public void applyLazyFields(MultiGetItemResponse response) { GetResponse getResponse = response.getResponse(); if(getResponse.isSourceEmpty()) return; setFields(getResponse.getSource()); }
private static void checkDocumentEquality(Map<String, Object> expectedDataOfDocument, GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) { final Map<String, Object> dataOfDocument = new LinkedHashMap<>(dataOfDocumentResponse.getSource()); if (!DeepEquals.deepEquals(dataOfDocument, expectedDataOfDocument)) { try { throw FailureHandler.createFailure("Expected document for index: %s - type: %s - id: %s is %s, but %s was found.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id(), OBJECT_MAPPER.writeValueAsString(expectedDataOfDocument), OBJECT_MAPPER.writeValueAsString(dataOfDocument)); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
private static void checkDocumentEquality(Map<String, Object> expectedDataOfDocument, GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) { final Map<String, Object> dataOfDocument = new LinkedHashMap<>(dataOfDocumentResponse.getSource()); if (!DeepEquals.deepEquals(dataOfDocument, expectedDataOfDocument)) { try { throw FailureHandler.createFailure("Expected document for index: %s - type: %s - id: %s is %s, but %s was found.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id(), OBJECT_MAPPER.writeValueAsString(expectedDataOfDocument), OBJECT_MAPPER.writeValueAsString(dataOfDocument)); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
public NamedQuery get(String name) { GetResponse response = getConnection().getClient() .prepareGet(getIndex(), getType(), name.toLowerCase()) .setFetchSource(true) .get(); if (response.isExists()) { return mapToNamedQuery(response.getSource()); } return null; }
public HttpSource get(String url) { GetResponse response = getConnection().getClient().prepareGet(getIndex(), getType(), url) .setFetchSource(true) .get(); if (response.isExists()) { return mapToHttpSource(response.getSource()); } return null; }
public HttpSourceTest get(String url) { GetResponse response = getConnection().getClient().prepareGet(getIndex(), getType(), url) .setFetchSource(true) .get(); if (response.isExists()) { return mapToHttpSourceTest(response.getSource()); } return null; }