本文整理汇总了Java中io.searchbox.core.Get类的典型用法代码示例。如果您正苦于以下问题:Java Get类的具体用法?Java Get怎么用?Java Get使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Get类属于io.searchbox.core包,在下文中一共展示了Get类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
protected Profile doInBackground(String... parameters){
verifySettings();
Profile profile = null;
Get get = new Get.Builder(appESIndex, parameters[0]).type("profile").build();
try {
JestResult result = client.execute(get);
if (result.isSucceeded()) {
profile = (result.getSourceAsObject(Profile.class));
}
}
catch (Exception e){
Log.i("Error", "ElasticSearch failed to find profile");
}
return profile;
}
示例2: doInBackground
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
protected Request doInBackground(String... params) {
verifySettings();
Get get = new Get.Builder("cmput301f16t01", params[0])
.type( "request" ).build();
try {
JestResult result = client.execute(get);
if (result.isSucceeded()) {
return result.getSourceAsObject(Request.class);
} else {
throw new IllegalArgumentException( result.getErrorMessage() );
}
} catch (IOException e) {
e.printStackTrace();
throw new IllegalArgumentException();
}
}
示例3: executeGet
import io.searchbox.core.Get; //导入依赖的package包/类
protected final Tuple<JestResult, HttpResponse> executeGet(final String index, final String type, final String id,
final boolean mustBeSuccesfull, final boolean connectFromLocalhost) throws Exception {
client = getJestClient(getServerUri(connectFromLocalhost), username, password);
final Tuple<JestResult, HttpResponse> restu = client.executeE(new Get.Builder(index, id).type(type).refresh(true)
.setHeader(headers).build());
final JestResult res = restu.v1();
if (mustBeSuccesfull) {
if (res.getErrorMessage() != null) {
log.error("Get operation result: {}", res.getErrorMessage());
}
Assert.assertTrue("Error msg: " + res.getErrorMessage() + res.getJsonString(), res.isSucceeded());
} else {
log.debug("Get operation result fails as expected");
Assert.assertTrue(!res.isSucceeded());
}
return restu;
}
示例4: getJsonById
import io.searchbox.core.Get; //导入依赖的package包/类
public String getJsonById(String id) throws IOException {
Flush flush = new Flush.Builder().build();
jestHttpClient.execute(flush);
long start = System.currentTimeMillis();
Get get = new Get.Builder(_esIndexName, id).build();
JestResult result = null;
try {
result = jestHttpClient.execute(get);
} catch (IOException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
LOG.info("->> GetJsonByID: search time --> " + (end - start) + " milliseconds");
return result.getJsonString();
}
示例5: checkCacheVersion
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* Checks the ES store to see if the 'dataVersion' entry has been updated with a newer
* version #. If it has, then we need to invalidate our cache.
*/
protected void checkCacheVersion() {
// Be very aggressive in invalidating the cache.
boolean invalidate = true;
try {
Get get = new Get.Builder(getDefaultIndexName(), "instance").type("dataVersion").build(); //$NON-NLS-1$ //$NON-NLS-2$
JestResult result = getClient().execute(get);
if (result.isSucceeded()) {
String latestDV = result.getJsonObject().get("_version").getAsString(); //$NON-NLS-1$
if (latestDV != null && dataVersion != null && latestDV.equals(dataVersion)) {
invalidate = false;
} else {
dataVersion = latestDV;
}
}
} catch (IOException e) {
// TODO need to use the gateway logger to log this!
e.printStackTrace();
}
if (invalidate) {
invalidateCache();
}
}
示例6: validateContract
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* Ensures that the api referenced by the Contract at the head of
* the iterator actually exists (is published).
* @param contract
* @param apiMap
*/
private void validateContract(final Contract contract)
throws RegistrationException {
final String id = getApiId(contract);
try {
Get get = new Get.Builder(getIndexName(), id).type("api").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
if (!result.isSucceeded()) {
String apiId = contract.getApiId();
String orgId = contract.getApiOrgId();
throw new ApiNotFoundException(Messages.i18n.format("ESRegistry.ApiNotFoundInOrg", apiId, orgId)); //$NON-NLS-1$
}
} catch (IOException e) {
throw new RegistrationException(Messages.i18n.format("ESRegistry.ErrorValidatingClient"), e); //$NON-NLS-1$
}
}
示例7: get
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
public IEsItem get(IEsItem doc) throws Exception {
Get.Builder builder = new Get.Builder(doc.getIndex(), doc.getId());
if (doc.getType() != null) {
builder.type(doc.getType());
}
DocumentResult result = _exec(builder.build());
if (result != null) {
return result.getSourceAsObject(doc.getClass());
}
return null;
}
示例8: doInBackground
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
protected User doInBackground(String... search_parameters) {
verifySettings();
Get get = new Get.Builder(INDEX, search_parameters[0]).type(USER).id(search_parameters[0]).build();
User user = null;
try {
JestResult result = client.execute(get);
user = result.getSourceAsObject(User.class);
} catch (IOException e) {
e.printStackTrace();
}
return user;
}
示例9: isValidDocumentIndex
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
public boolean isValidDocumentIndex(String indexName, String documentType, String id, String json)
{
Get get = new Get.Builder(indexName, id).type(documentType).build();
JestResult jestResult = jestClientHelper.executeAction(get);
// Retrieve the JSON string from the get response
final String jsonStringFromIndex = jestResult.getSourceAsString();
// Return true if the json from the index is not null or empty and the json from the index matches the object from the database
return StringUtils.isNotEmpty(jsonStringFromIndex) && jsonStringFromIndex.equals(json);
}
示例10: get
import io.searchbox.core.Get; //导入依赖的package包/类
public <T extends EsEntity<?>> Optional<T> get(Class<T> cls, String id) {
DocumentResult result = execute(
new Get.Builder(EsNameHelper.index(cls), id).type(EsNameHelper.type(cls)).build());
if (result.isSucceeded()) {
T entity = result.getSourceAsObject(cls);
entity.setId(id);
entity.setVersion(result.getJsonObject().get("_version").getAsLong());
return Optional.of(entity);
}
return Optional.empty();
}
示例11: getEntity
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* Gets an entity. Callers must unmarshal the resulting map.
* @param type
* @param id
* @throws StorageException
*/
private Map<String, Object> getEntity(String type, String id) throws StorageException {
try {
JestResult response = esClient.execute(new Get.Builder(getIndexName(), id).type(type).build());
if (!response.isSucceeded()) {
return null;
}
return response.getSourceAsObject(Map.class);
} catch (Exception e) {
throw new StorageException(e);
}
}
示例12: accept
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.components.IRateLimiterComponent#accept(java.lang.String, io.apiman.gateway.engine.rates.RateBucketPeriod, long, long, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
public void accept(final String bucketId, final RateBucketPeriod period, final long limit,
final long increment, final IAsyncResultHandler<RateLimitResponse> handler) {
final String id = id(bucketId);
try {
Get get = new Get.Builder(getIndexName(), id).type("rateBucket").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
RateLimiterBucket bucket;
long version;
if (result.isSucceeded()) {
// use the existing bucket
version = result.getJsonObject().get("_version").getAsLong(); //$NON-NLS-1$
bucket = result.getSourceAsObject(RateLimiterBucket.class);
} else {
// make a new bucket
version = 0;
bucket = new RateLimiterBucket();
}
bucket.resetIfNecessary(period);
final RateLimitResponse rlr = new RateLimitResponse();
if (bucket.getCount() > limit) {
rlr.setAccepted(false);
} else {
rlr.setAccepted(bucket.getCount() < limit);
bucket.setCount(bucket.getCount() + increment);
bucket.setLast(System.currentTimeMillis());
}
int reset = (int) (bucket.getResetMillis(period) / 1000L);
rlr.setReset(reset);
rlr.setRemaining(limit - bucket.getCount());
updateBucketAndReturn(id, bucket, rlr, version, bucketId, period, limit, increment, handler);
} catch (Throwable e) {
handler.handle(AsyncResultImpl.create(e, RateLimitResponse.class));
}
}
示例13: getApi
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* Gets the api synchronously.
* @param id
* @throws IOException
*/
protected Api getApi(String id) throws IOException {
Get get = new Get.Builder(getIndexName(), id).type("api").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
if (result.isSucceeded()) {
Api api = result.getSourceAsObject(Api.class);
return api;
} else {
return null;
}
}
示例14: getClient
import io.searchbox.core.Get; //导入依赖的package包/类
/**
* Gets the client synchronously.
* @param id
* @throws IOException
*/
protected Client getClient(String id) throws IOException {
Get get = new Get.Builder(getIndexName(), id).type("client").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
if (result.isSucceeded()) {
Client client = result.getSourceAsObject(Client.class);
return client;
} else {
return null;
}
}
示例15: getByUid
import io.searchbox.core.Get; //导入依赖的package包/类
@Override
public AddOnInfoAndVersions getByUid(String uid) throws IOException {
return client.execute(new Get.Builder(AddOnInfoAndVersions.ES_INDEX, uid).build())
.getSourceAsObject(AddOnInfoAndVersions.class);
}