本文整理了Java中org.elasticsearch.client.Client.prepareGet()
方法的一些代码示例,展示了Client.prepareGet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.prepareGet()
方法的具体详情如下:
包路径:org.elasticsearch.client.Client
类名称:Client
方法名:prepareGet
[英]Gets the document that was indexed from an index with a type and id.
[中]获取从具有类型和id的索引编制索引的文档。
代码示例来源:origin: loklak/loklak_server
/**
* 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;
}
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
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());
}
}
代码示例来源:origin: brianfrankcooper/YCSB
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();
代码示例来源:origin: brianfrankcooper/YCSB
public Status update(String table, String key, Map<String, ByteIterator> values) {
try {
final GetResponse response = client.prepareGet(indexKey, table, key).execute().actionGet();
代码示例来源:origin: loklak/loklak_server
.prepareGet(indexName, typeName, id)
.setOperationThreaded(false)
.setFields(new String[]{})
代码示例来源:origin: alibaba/jstorm
@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);
}
}
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
/**
* 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;
}
代码示例来源:origin: floragunncom/search-guard
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);
}
}
代码示例来源:origin: apache/nifi
final long startNanos = System.nanoTime();
GetRequestBuilder getRequestBuilder = esClient.get().prepareGet(index, docType, docId);
if (authToken != null) {
getRequestBuilder.putHeader("Authorization", authToken);
代码示例来源:origin: apache/nifi
GetRequestBuilder getRequestBuilder = esClient.get().prepareGet(index, docType, docId);
final GetResponse getResponse = getRequestBuilder.execute().actionGet();
代码示例来源:origin: Netflix/conductor
.prepareGet(searchHit.getIndex(), MSG_DOC_TYPE, searchHit.getId())
.get();
assertEquals("indexed message id should match", messageId, response.getSource().get("messageId"));
代码示例来源:origin: Netflix/conductor
.prepareGet(searchHit.getIndex(), EVENT_DOC_TYPE, searchHit.getId())
.get();
代码示例来源:origin: yacy/yacy_grid_mcp
/**
* 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;
}
代码示例来源:origin: yacy/yacy_grid_mcp
/**
* 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();
}
代码示例来源:origin: yacy/yacy_grid_mcp
/**
* 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;
}
代码示例来源:origin: larsga/Duke
@Override
public Record findRecordById(String id) {
GetResponse getResponse = client
.prepareGet(this.indexName, this.indexType, id).execute()
.actionGet();
return this
.readFromSource(getResponse.getId(), getResponse.getSource());
}
代码示例来源:origin: yacy/yacy_grid_mcp
.prepareGet(indexName, typeName, id)
.setOperationThreaded(false)
.execute()
代码示例来源:origin: komoot/photon
@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);
}
}
代码示例来源:origin: Netflix/metacat
/**
* {@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;
}
代码示例来源:origin: com.github.tlrx/elasticsearch-test
@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();
}
}
内容来源于网络,如有侵权,请联系作者删除!