本文整理汇总了Java中org.elasticsearch.action.get.GetRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java GetRequestBuilder类的具体用法?Java GetRequestBuilder怎么用?Java GetRequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetRequestBuilder类属于org.elasticsearch.action.get包,在下文中一共展示了GetRequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSource
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
/**
* Returns the source (a map of fields and values) for and object.
* The source is extracted from the index directly not the data store.
* @param appid name of the {@link com.erudika.para.core.App}
* @param key the object id
* @return a map representation of the object
*/
protected Map<String, Object> getSource(String appid, String key) {
Map<String, Object> map = new HashMap<String, Object>();
if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) {
return map;
}
try {
GetRequestBuilder grb = client().prepareGet().setIndex(getIndexName(appid)).setId(key);
GetResponse gres = grb.execute().actionGet();
if (gres.isExists()) {
map = gres.getSource();
}
} catch (IndexNotFoundException ex) {
logger.warn("Index not created yet. Call '_setup' first.");
} catch (Exception e) {
Throwable cause = e.getCause();
String msg = cause != null ? cause.getMessage() : e.getMessage();
logger.warn("Could not get any data from index '{}': {}", appid, msg);
}
return map;
}
示例2: loadExistingDocumentHistory
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
protected ElasticsearchDocumentHistory loadExistingDocumentHistory(String documentId) throws BaleenException {
try {
GetResponse response = new GetRequestBuilder(elasticsearch.getClient(), GetAction.INSTANCE).setId(documentId).setIndex(esIndex)
.setType(esType).get();
if (!response.isExists() || response.isSourceEmpty()) {
// If we don't have any data, then let parent implementation create a new history
return null;
} else {
ESHistory esh = mapper.readValue(response.getSourceAsBytes(), ESHistory.class);
if(esh == null){
return new ElasticsearchDocumentHistory(this, documentId, new LinkedBlockingDeque<HistoryEvent>(
Collections.emptyList()));
}else{
return new ElasticsearchDocumentHistory(this, documentId, new LinkedBlockingDeque<HistoryEvent>(
esh.getEvents()));
}
}
} catch (IOException e) {
throw new BaleenException(e);
}
}
示例3: getInstance
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override public Instance getInstance(int instanceId) {
logger.debug("get instance info, instance id: {}", instanceId);
GetRequestBuilder requestBuilder = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId));
GetResponse getResponse = requestBuilder.get();
if (getResponse.isExists()) {
Instance instance = new Instance();
instance.setId(getResponse.getId());
instance.setApplicationId(((Number)getResponse.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
instance.setAgentUUID((String)getResponse.getSource().get(InstanceTable.COLUMN_AGENT_UUID));
instance.setRegisterTime(((Number)getResponse.getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue());
instance.setHeartBeatTime(((Number)getResponse.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
instance.setOsInfo((String)getResponse.getSource().get(InstanceTable.COLUMN_OS_INFO));
return instance;
}
return null;
}
示例4: getById
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public <T> T getById(Class<T> clazz, String id, @Nullable String routing) {
String typeName = MappingProcessor.getIndexTypeName(clazz);
if (logger.isDebugEnabled()) {
logger.debug("Get object by id, class: {}, type: {}, id: {}, routing: {}", clazz.getSimpleName(), typeName, id, routing);
}
GetRequestBuilder getRequest = client.prepareGet(getIndexName(), typeName, id);
if (routing != null) {
getRequest.setRouting(routing);
}
GetResponse response = getRequest.get();
if (!response.isExists()) {
return null;
}
return objectProcessor.fromJsonString(response.getSourceAsString(), clazz);
}
示例5: transform
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public String[] transform(InputRow row) {
try {
final ElasticSearchDataContext dataContext = (ElasticSearchDataContext) _connection.getDataContext();
final Client client = dataContext.getElasticSearchClient();
final String[] result = new String[fields.length];
final String id = ConvertToStringTransformer.transformValue(row.getValue(documentId));
logger.info("Id is {}", id);
if (StringUtils.isNullOrEmpty(id)) {
return result;
}
final GetRequest request = new GetRequestBuilder(client).setId(id).setType(documentType).setFields(fields)
.setIndex(elasticsearchDatastore.getIndexName()).setOperationThreaded(false).request();
final ActionFuture<GetResponse> getFuture = client.get(request);
final GetResponse response = getFuture.actionGet();
logger.info("Response is {}", response);
if (!response.isExists()) {
return result;
}
for (int i = 0; i < fields.length; i++) {
final String field = fields[i];
final GetField valueGetter = response.getField(field);
if (valueGetter == null) {
logger.info("Document with id '{}' did not have the field '{}'", id, field);
} else {
final Object value = valueGetter.getValue();
result[i] = ConvertToStringTransformer.transformValue(value);
}
}
return result;
} catch (Exception e) {
logger.error("Exception while running the ElasticSearchDocumentIdLookupTransformer", e);
throw e;
}
}
开发者ID:datacleaner,项目名称:extension_elasticsearch,代码行数:41,代码来源:ElasticSearchDocumentIdLookupTransformer.java
示例6: getDocument
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
private GetResponse getDocument(String index, String type, String docId, String field, @Nullable String routing) {
GetRequestBuilder getRequestBuilder = client().prepareGet().setIndex(index).setType(type).setId(docId).setStoredFields(field);
if (routing != null) {
getRequestBuilder.setRouting(routing);
}
return getRequestBuilder.get();
}
示例7: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Optional<PersistentServiceDef>> call(final String id) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Request {%s,%s,%s}", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id));
}
GetRequestBuilder request = elasticSearch.get()
.prepareGet(
elasticSearch.serviceDefTypeIndex(),
elasticSearch.defaultType(),
id);
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
return fromNullable(fromGetResponse(getResponse));
} else {
return absent();
}
});
}
示例8: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Optional<PersistentAccount>> call(final String accountId) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Request {%s,%s}", elasticSearch.defaultType(), elasticSearch.accountIndex(), accountId));
}
GetRequestBuilder request =
elasticSearch.get()
.prepareGet(
elasticSearch.accountIndex(),
elasticSearch.defaultType(),
accountId);
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Response {%s,%s} = %s", getResponse.getType(), elasticSearch.accountIndex(), accountId, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
return of(fromGetResponse(getResponse));
} else {
return absent();
}
});
}
示例9: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Optional<PersistentMasterKey>> call(String id) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
GetRequestBuilder request = elasticSearch.get()
.prepareGet(
elasticSearch.masterKeyTypeIndex(),
elasticSearch.defaultType(),
id);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Search Request {%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), Jsonify.toString(request)));
}
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), id, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
return of(fromGetResponse(getResponse));
} else {
return absent();
}
});
}
示例10: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Holder3<PersistentContainer, String, Optional<PersistentContainerKey>>> call(final Holder2<PersistentContainer, String> input) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
final String id = input.value1();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Request {%s,%s,%s}", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), id));
}
GetRequestBuilder request = elasticSearch.get()
.prepareGet(
elasticSearch.containerKeyIndex(),
elasticSearch.defaultType(),
id);
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
Holder3<PersistentContainer, String, Optional<PersistentContainerKey>> output = new Holder3<>();
output.value0(input.value0());
output.value1(input.value1());
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), id, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
output.value2 = of(fromGetResponse(input.value0(), getResponse));
} else {
output.value2 = absent();
}
return output;
});
}
示例11: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Optional<PersistentObject>> call(String objectId) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
String objectIndex = elasticSearch.objectIndex(persistentContainer.getName());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Request {%s,%s,%s}", elasticSearch.defaultType(), objectIndex, objectId));
}
GetRequestBuilder request = elasticSearch.get()
.prepareGet(
objectIndex,
elasticSearch.defaultType(),
objectId);
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Response {%s,%s,%s} = %s", elasticSearch.defaultType(), objectIndex, objectId, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
return of(fromGetResponse(persistentContainer, getResponse));
} else {
return absent();
}
});
}
示例12: call
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Optional<PersistentContainer>> call(String containerId) {
final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Request {%s,%s,%s}", elasticSearch.defaultType(), elasticSearch.containerIndex(), containerId));
}
GetRequestBuilder request = elasticSearch.get()
.prepareGet(
elasticSearch.containerIndex(),
elasticSearch.defaultType(),
containerId);
return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultGetTimeout())
.map(oGetResponse -> {
GetResponse getResponse = oGetResponse.get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Get Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), containerId, Jsonify.toString(getResponse)));
}
if (getResponse.isExists()) {
return of(fromGetResponse(account, getResponse));
} else {
return absent();
}
});
}
示例13: documentExists
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
public boolean documentExists(final String index, final String type, final String id) {
LOGGER.trace("Checking for existence of document: '{}/{}/{}'", index, type, id);
GetRequestBuilder builder = client.prepareGet()
.setIndex(index)
.setType(type)
.setId(id)
.setFields(new String[] {});
addCommonHeaders(builder);
GetResponse response = builder.get();
final boolean exists = response.isExists();
LOGGER.trace("Document '{}/{}/{}' exists? {}", index, type, id, exists);
return exists;
}
示例14: shouldTestIfEntityExistsAndReturnTrue
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Test
public void shouldTestIfEntityExistsAndReturnTrue() throws Exception {
// GIVEN
// a fake index and type names
String index = "fakeindex";
String type = "faketype";
String id = "123456";
// an elasticsearch getresponse returning true on isExists
GetResponse response = mock(GetResponse.class);
when(response.isExists()).thenReturn(true);
// an elasticsearch client return a mocked request builder with mocked action and previously defined response injected
ListenableActionFuture<GetResponse> action = mock(ListenableActionFuture.class);
when(action.actionGet()).thenReturn(response);
GetRequestBuilder reqBuilder = mock(GetRequestBuilder.class);
when(reqBuilder.execute()).thenReturn(action);
when(client.prepareGet(anyString(), anyString(), anyString())).thenReturn(reqBuilder);
// an elasticsearch storage
ElasticsearchStorage<FakeEntity> storage = new ElasticsearchStorage<>(
client,
mapper,
index,
type
);
// WHEN
boolean output = storage.exists(id);
// THEN
assertThat(output).isTrue();
verify(client, times(1)).prepareGet(index, type, id);
verify(reqBuilder, times(1)).execute();
}
示例15: shouldThrowAnAlreadyExistsExceptionWhenCreatingAnEntityWithCustomIdButItAlreadyExists
import org.elasticsearch.action.get.GetRequestBuilder; //导入依赖的package包/类
@Test
public void shouldThrowAnAlreadyExistsExceptionWhenCreatingAnEntityWithCustomIdButItAlreadyExists() throws Exception {
// GIVEN
// a fake index and type names
String index = "fakeindex";
String type = "faketype";
// GET MOCKING:a mocked get response saying that entity already exists
GetResponse getResponse = mock(GetResponse.class);
when(getResponse.isExists()).thenReturn(true);
// GET MOCKING: a mocked get request builder
ListenableActionFuture<GetResponse> getAction = mock(ListenableActionFuture.class);
when(getAction.actionGet()).thenReturn(getResponse);
GetRequestBuilder getReqBuilder = mock(GetRequestBuilder.class);
when(getReqBuilder.execute()).thenReturn(getAction);
when(client.prepareGet(anyString(), anyString(), anyString())).thenReturn(getReqBuilder);
// an elasticsearch storage
ElasticsearchStorage<FakeEntity> storage = new ElasticsearchStorage<>(
client,
mapper,
index,
type
);
// an entity
FakeEntity entity = new FakeEntity("123456789");
try {
// WHEN
storage.store(entity, entity.getId());
throw fail("should throw a AlreadyExistsException");
} catch (AlreadyExistsException e) {
// THEN
verify(client, times(1)).prepareGet(index, type, entity.getId());
verify(getReqBuilder, times(1)).execute();
}
}