/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(String indexName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); Map<String, Object> map = getMap(response); return map; }
public static Status getRiverStatus(Client client, String riverName) { GetResponse statusResponse = client.prepareGet("_river", riverName, MongoDBRiver.STATUS_ID).get(); if (!statusResponse.isExists()) { return Status.UNKNOWN; } else { Object obj = XContentMapValues.extractValue(MongoDBRiver.TYPE + "." + MongoDBRiver.STATUS_FIELD, statusResponse.getSourceAsMap()); return Status.valueOf(obj.toString()); } }
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { final GetResponse response = client.prepareGet(indexKey, table, key).execute().actionGet();
public Status update(String table, String key, Map<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key).execute().actionGet();
.prepareGet(indexName, typeName, id) .setOperationThreaded(false) .setFields(new String[]{})
@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); } }
/** * Get the latest timestamp for a given namespace. */ @SuppressWarnings("unchecked") public static Timestamp<?> getLastTimestamp(Client client, MongoDBRiverDefinition definition) { client.admin().indices().prepareRefresh(definition.getRiverIndexName()).get(); GetResponse lastTimestampResponse = client.prepareGet(definition.getRiverIndexName(), definition.getRiverName(), definition.getMongoOplogNamespace()).get(); if (lastTimestampResponse.isExists()) { Map<String, Object> mongodbState = (Map<String, Object>) lastTimestampResponse.getSourceAsMap().get(TYPE); if (mongodbState != null) { Timestamp<?> lastTimestamp = Timestamp.on(mongodbState); if (lastTimestamp != null) { return lastTimestamp; } } } else { if (definition.getInitialTimestamp() != null) { return definition.getInitialTimestamp(); } } return null; }
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); } }
final long startNanos = System.nanoTime(); GetRequestBuilder getRequestBuilder = esClient.get().prepareGet(index, docType, docId); if (authToken != null) { getRequestBuilder.putHeader("Authorization", authToken);
GetRequestBuilder getRequestBuilder = esClient.get().prepareGet(index, docType, docId); final GetResponse getResponse = getRequestBuilder.execute().actionGet();
.prepareGet(searchHit.getIndex(), MSG_DOC_TYPE, searchHit.getId()) .get(); assertEquals("indexed message id should match", messageId, response.getSource().get("messageId"));
.prepareGet(searchHit.getIndex(), EVENT_DOC_TYPE, searchHit.getId()) .get();
/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(final String indexName, final String typeName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, typeName, id).execute().actionGet(); Map<String, Object> map = getMap(response); return map; }
/** * Read a document from the search index for a given id. * This is the cheapest document retrieval from the '_source' field because * elasticsearch does not do any json transformation or parsing. We * get simply the text from the '_source' field. This might be useful to * make a dump from the index content. * * @param id * the unique identifier of a document * @return the document as source text */ public byte[] readSource(String indexName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); return response.getSourceAsBytes(); }
/** * 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; }
@Override public Record findRecordById(String id) { GetResponse getResponse = client .prepareGet(this.indexName, this.indexType, id).execute() .actionGet(); return this .readFromSource(getResponse.getId(), getResponse.getSource()); }
.prepareGet(indexName, typeName, id) .setOperationThreaded(false) .execute()
@Override public void updateOrCreate(PhotonDoc updatedDoc) { final boolean exists = this.esClient.get(this.esClient.prepareGet("photon", "place", String.valueOf(updatedDoc.getPlaceId())).request()).actionGet().isExists(); if (exists) { this.update(updatedDoc); } else { this.create(updatedDoc); } }
/** * {@inheritDoc} */ @Override public ElasticSearchDoc get(final String type, final String id, final String index) { ElasticSearchDoc result = null; final GetResponse response = client.prepareGet(index, type, id).execute().actionGet(esCallTimeout); if (response.isExists()) { result = parse(response); } return result; }
@Override public Boolean execute(Client client) throws ElasticsearchException { if ((index != null) && (type != null) && (id != null)) { // Check if a document exists GetResponse response = client.prepareGet(index, type, id).setRefresh(true).execute().actionGet(); return response.isExists(); } else { // Check if index exists IndicesExistsResponse response = client.admin().indices().prepareExists(index).execute().actionGet(); return response.isExists(); } }