当前位置: 首页>>代码示例>>Java>>正文


Java GetResponse.isExists方法代码示例

本文整理汇总了Java中org.elasticsearch.action.get.GetResponse.isExists方法的典型用法代码示例。如果您正苦于以下问题:Java GetResponse.isExists方法的具体用法?Java GetResponse.isExists怎么用?Java GetResponse.isExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.get.GetResponse的用法示例。


在下文中一共展示了GetResponse.isExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryByMultiGet

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
 * 获取多个对象(根据ID)
 *
 * @param transportClient
 * @throws IOException
 */
private static void queryByMultiGet(TransportClient transportClient) throws IOException {

	MultiGetResponse multiGetItemResponses = transportClient.prepareMultiGet()
			.add("product_index", "product", "1")
			.add("product_index", "product", "2")
			.add("product_index", "product", "3")
			.add("product_index", "product", "4")
			.add("product_index", "product", "5")
			.get();

	String resultJSON = null;
	for (MultiGetItemResponse multiGetItemResponse : multiGetItemResponses) {
		GetResponse getResponse = multiGetItemResponse.getResponse();
		if (getResponse.isExists()) {
			resultJSON = getResponse.getSourceAsString();
		}
	}
	logger.info("--------------------------------:" + resultJSON);
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:26,代码来源:BaseDemo.java

示例2: getFact

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
 * Retrieve an indexed Fact by its UUID. Returns NULL if Fact cannot be fetched from ElasticSearch.
 *
 * @param id UUID of indexed Fact
 * @return Indexed Fact or NULL if not available
 */
public FactDocument getFact(UUID id) {
  if (id == null) return null;
  GetResponse response;

  try {
    GetRequest request = new GetRequest(INDEX_NAME, TYPE_NAME, id.toString());
    response = clientFactory.getHighLevelClient().get(request);
  } catch (IOException ex) {
    throw logAndExit(ex, String.format("Could not perform request to fetch Fact with id = %s.", id));
  }

  if (response.isExists()) {
    LOGGER.info("Successfully fetched Fact with id = %s.", id);
    return decodeFactDocument(id, response.getSourceAsBytes());
  } else {
    // Fact isn't indexed in ElasticSearch, log warning and return null.
    LOGGER.warning("Could not fetch Fact with id = %s. Fact not indexed?", id);
    return null;
  }
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:27,代码来源:FactSearchManager.java

示例3: getSource

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的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;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:29,代码来源:ElasticSearch.java

示例4: doStore

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private void doStore(Task parentTask, GetResponse response, CreateModelFromSetRequest request,
                     ActionListener<CreateModelFromSetResponse> listener) {
    if (!response.isExists()) {
        throw new IllegalArgumentException("Stored feature set [" + request.getFeatureSetName() + "] does not exist");
    }
    if (request.getExpectedSetVersion() != null && request.getExpectedSetVersion() != response.getVersion()) {
        throw new IllegalArgumentException("Stored feature set [" + request.getFeatureSetName() + "]" +
                " has version [" + response.getVersion() + "] but [" + request.getExpectedSetVersion() + "] was expected.");
    }
    final StoredFeatureSet set;
    try {
        set = IndexFeatureStore.parse(StoredFeatureSet.class, StoredFeatureSet.TYPE, response.getSourceAsBytesRef());
    } catch(IOException ioe) {
        throw new IllegalStateException("Cannot parse stored feature set [" + request.getFeatureSetName() + "]", ioe);
    }
    // Model will be parsed & checked by TransportFeatureStoreAction
    StoredLtrModel model = new StoredLtrModel(request.getModelName(), set, request.getDefinition());
    FeatureStoreRequest featureStoreRequest = new FeatureStoreRequest(request.getStore(), model, FeatureStoreRequest.Action.CREATE);
    featureStoreRequest.setRouting(request.getRouting());
    featureStoreRequest.setParentTask(clusterService.localNode().getId(), parentTask.getId());
    featureStoreRequest.setValidation(request.getValidation());
    featureStoreAction.execute(featureStoreRequest, ActionListener.wrap(
            (r) -> listener.onResponse(new CreateModelFromSetResponse(r.getResponse())),
            listener::onFailure));

}
 
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:27,代码来源:TransportCreateModelFromSetAction.java

示例5: onGetResponse

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private void onGetResponse(GetResponse getResponse) {
    try {
        StoredFeatureSet featureSet;
        if (getResponse.isExists()) {
            version.set(getResponse.getVersion());
            featureSet = IndexFeatureStore.parse(StoredFeatureSet.class, StoredFeatureSet.TYPE, getResponse.getSourceAsBytesRef());
        } else {
            version.set(-1L);
            featureSet = new StoredFeatureSet(featureSetName, Collections.emptyList());
        }
        setRef.set(featureSet);
    } catch (Exception e) {
        getException.set(e);
    } finally {
        maybeFinish();
    }
}
 
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:18,代码来源:TransportAddFeatureToSetAction.java

示例6: processGet

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
 * Processes a "get" request.
 * 
 * @param urlItems Items of the URL
 * @return Result of the get request, it contains a JSON-formatted string
 */
private InterpreterResult processGet(String[] urlItems) {

  if (urlItems.length != 3 
      || StringUtils.isEmpty(urlItems[0]) 
      || StringUtils.isEmpty(urlItems[1]) 
      || StringUtils.isEmpty(urlItems[2])) {
    return new InterpreterResult(InterpreterResult.Code.ERROR,
                                 "Bad URL (it should be /index/type/id)");
  }

  final GetResponse response = client
    .prepareGet(urlItems[0], urlItems[1], urlItems[2])
    .get();
  if (response.isExists()) {
    final String json = gson.toJson(response.getSource());

    return new InterpreterResult(
                  InterpreterResult.Code.SUCCESS,
                  InterpreterResult.Type.TEXT,
                  json);
  }
      
  return new InterpreterResult(InterpreterResult.Code.ERROR, "Document not found");
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:31,代码来源:ElasticsearchInterpreter.java

示例7: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public Optional<T> get(GetRequest request) {
    StopWatch watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    int hits = 0;
    try {
        GetResponse response = client().prepareGet(index, type, request.id).get();
        if (!response.isExists()) return Optional.empty();
        hits = 1;
        return Optional.of(reader.fromJSON(response.getSourceAsBytes()));
    } catch (ElasticsearchException e) {
        throw new SearchException(e);   // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("elasticsearch", elapsedTime, hits, 0);
        logger.debug("get, index={}, type={}, id={}, elapsedTime={}", index, type, request.id, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:20,代码来源:ElasticSearchTypeImpl.java

示例8: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public InstanceAlarmList get(String id) {
    GetResponse getResponse = getClient().prepareGet(InstanceAlarmListTable.TABLE, id).get();
    if (getResponse.isExists()) {
        InstanceAlarmList instanceAlarmList = new InstanceAlarmList();
        instanceAlarmList.setId(id);
        Map<String, Object> source = getResponse.getSource();
        instanceAlarmList.setApplicationId(((Number)source.get(InstanceAlarmListTable.COLUMN_APPLICATION_ID)).intValue());
        instanceAlarmList.setInstanceId(((Number)source.get(InstanceAlarmListTable.COLUMN_INSTANCE_ID)).intValue());
        instanceAlarmList.setSourceValue(((Number)source.get(InstanceAlarmListTable.COLUMN_SOURCE_VALUE)).intValue());

        instanceAlarmList.setAlarmType(((Number)source.get(InstanceAlarmListTable.COLUMN_ALARM_TYPE)).intValue());
        instanceAlarmList.setAlarmContent((String)source.get(InstanceAlarmListTable.COLUMN_ALARM_CONTENT));

        instanceAlarmList.setTimeBucket(((Number)source.get(InstanceAlarmListTable.COLUMN_TIME_BUCKET)).longValue());
        return instanceAlarmList;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:20,代码来源:InstanceAlarmListEsPersistenceDAO.java

示例9: getById

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
Optional<Credentials> getById(String id, boolean throwNotFound) {
	Credentials credentials = SpaceContext.getCredentials();

	if (id.equals(credentials.id()))
		return Optional.of(credentials);

	GetResponse response = Start.get().getElasticClient().get(SPACEDOG_BACKEND, TYPE, id);

	if (response.isExists())
		return Optional.of(toCredentials(response));

	if (throwNotFound)
		throw Exceptions.notFound(credentials.backendId(), TYPE, id);
	else
		return Optional.empty();
}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:17,代码来源:CredentialsResource.java

示例10: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public ApplicationAlarmList get(String id) {
    GetResponse getResponse = getClient().prepareGet(ApplicationAlarmListTable.TABLE, id).get();
    if (getResponse.isExists()) {
        ApplicationAlarmList applicationAlarmList = new ApplicationAlarmList();
        applicationAlarmList.setId(id);
        Map<String, Object> source = getResponse.getSource();
        applicationAlarmList.setApplicationId(((Number)source.get(ApplicationAlarmListTable.COLUMN_APPLICATION_ID)).intValue());
        applicationAlarmList.setSourceValue(((Number)source.get(ApplicationAlarmListTable.COLUMN_SOURCE_VALUE)).intValue());

        applicationAlarmList.setAlarmType(((Number)source.get(ApplicationAlarmListTable.COLUMN_ALARM_TYPE)).intValue());
        applicationAlarmList.setAlarmContent((String)source.get(ApplicationAlarmListTable.COLUMN_ALARM_CONTENT));

        applicationAlarmList.setTimeBucket(((Number)source.get(ApplicationAlarmListTable.COLUMN_TIME_BUCKET)).longValue());
        return applicationAlarmList;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:19,代码来源:ApplicationAlarmListEsPersistenceDAO.java

示例11: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public ServiceAlarm get(String id) {
    GetResponse getResponse = getClient().prepareGet(ServiceAlarmTable.TABLE, id).get();
    if (getResponse.isExists()) {
        ServiceAlarm serviceAlarm = new ServiceAlarm();
        serviceAlarm.setId(id);
        Map<String, Object> source = getResponse.getSource();
        serviceAlarm.setApplicationId(((Number)source.get(ServiceAlarmTable.COLUMN_APPLICATION_ID)).intValue());
        serviceAlarm.setInstanceId(((Number)source.get(ServiceAlarmTable.COLUMN_INSTANCE_ID)).intValue());
        serviceAlarm.setServiceId(((Number)source.get(ServiceAlarmTable.COLUMN_SERVICE_ID)).intValue());
        serviceAlarm.setSourceValue(((Number)source.get(ServiceAlarmTable.COLUMN_SOURCE_VALUE)).intValue());

        serviceAlarm.setAlarmType(((Number)source.get(ServiceAlarmTable.COLUMN_ALARM_TYPE)).intValue());
        serviceAlarm.setAlarmContent((String)source.get(ServiceAlarmTable.COLUMN_ALARM_CONTENT));

        serviceAlarm.setLastTimeBucket(((Number)source.get(ServiceAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue());
        return serviceAlarm;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:21,代码来源:ServiceAlarmEsPersistenceDAO.java

示例12: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public ServiceReferenceAlarmList get(String id) {
    GetResponse getResponse = getClient().prepareGet(ServiceReferenceAlarmListTable.TABLE, id).get();
    if (getResponse.isExists()) {
        ServiceReferenceAlarmList serviceReferenceAlarmList = new ServiceReferenceAlarmList();
        serviceReferenceAlarmList.setId(id);
        Map<String, Object> source = getResponse.getSource();
        serviceReferenceAlarmList.setFrontApplicationId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_FRONT_APPLICATION_ID)).intValue());
        serviceReferenceAlarmList.setBehindApplicationId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_BEHIND_APPLICATION_ID)).intValue());
        serviceReferenceAlarmList.setFrontInstanceId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_FRONT_INSTANCE_ID)).intValue());
        serviceReferenceAlarmList.setBehindInstanceId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_BEHIND_INSTANCE_ID)).intValue());
        serviceReferenceAlarmList.setFrontServiceId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_FRONT_SERVICE_ID)).intValue());
        serviceReferenceAlarmList.setBehindServiceId(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_BEHIND_SERVICE_ID)).intValue());
        serviceReferenceAlarmList.setSourceValue(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_SOURCE_VALUE)).intValue());

        serviceReferenceAlarmList.setAlarmType(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_ALARM_TYPE)).intValue());
        serviceReferenceAlarmList.setAlarmContent((String)source.get(ServiceReferenceAlarmListTable.COLUMN_ALARM_CONTENT));

        serviceReferenceAlarmList.setTimeBucket(((Number)source.get(ServiceReferenceAlarmListTable.COLUMN_TIME_BUCKET)).longValue());
        return serviceReferenceAlarmList;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:24,代码来源:ServiceReferenceAlarmListEsPersistenceDAO.java

示例13: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public Instance get(String id) {
    GetResponse getResponse = getClient().prepareGet(InstanceTable.TABLE, id).get();
    if (getResponse.isExists()) {
        Map<String, Object> source = getResponse.getSource();

        Instance instance = new Instance();
        instance.setId(id);
        instance.setInstanceId(((Number)source.get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
        instance.setHeartBeatTime(((Number)source.get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
        logger.debug("getId: {} is exists", id);
        return instance;
    } else {
        logger.debug("getId: {} is not exists", id);
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:17,代码来源:InstanceHeartBeatEsPersistenceDAO.java

示例14: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public InstanceReferenceAlarm get(String id) {
    GetResponse getResponse = getClient().prepareGet(InstanceReferenceAlarmTable.TABLE, id).get();
    if (getResponse.isExists()) {
        InstanceReferenceAlarm instanceReferenceAlarm = new InstanceReferenceAlarm();
        instanceReferenceAlarm.setId(id);
        Map<String, Object> source = getResponse.getSource();
        instanceReferenceAlarm.setFrontApplicationId(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_FRONT_APPLICATION_ID)).intValue());
        instanceReferenceAlarm.setBehindApplicationId(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_BEHIND_APPLICATION_ID)).intValue());
        instanceReferenceAlarm.setFrontInstanceId(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_FRONT_INSTANCE_ID)).intValue());
        instanceReferenceAlarm.setBehindInstanceId(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_BEHIND_INSTANCE_ID)).intValue());
        instanceReferenceAlarm.setSourceValue(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_SOURCE_VALUE)).intValue());

        instanceReferenceAlarm.setAlarmType(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_ALARM_TYPE)).intValue());
        instanceReferenceAlarm.setAlarmContent((String)source.get(InstanceReferenceAlarmTable.COLUMN_ALARM_CONTENT));

        instanceReferenceAlarm.setLastTimeBucket(((Number)source.get(InstanceReferenceAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue());
        return instanceReferenceAlarm;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:22,代码来源:InstanceReferenceAlarmEsPersistenceDAO.java

示例15: get

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override public ServiceAlarmList get(String id) {
    GetResponse getResponse = getClient().prepareGet(ServiceAlarmListTable.TABLE, id).get();
    if (getResponse.isExists()) {
        ServiceAlarmList serviceAlarmList = new ServiceAlarmList();
        serviceAlarmList.setId(id);
        Map<String, Object> source = getResponse.getSource();
        serviceAlarmList.setApplicationId(((Number)source.get(ServiceAlarmListTable.COLUMN_APPLICATION_ID)).intValue());
        serviceAlarmList.setInstanceId(((Number)source.get(ServiceAlarmListTable.COLUMN_INSTANCE_ID)).intValue());
        serviceAlarmList.setServiceId(((Number)source.get(ServiceAlarmListTable.COLUMN_SERVICE_ID)).intValue());
        serviceAlarmList.setSourceValue(((Number)source.get(ServiceAlarmListTable.COLUMN_SOURCE_VALUE)).intValue());

        serviceAlarmList.setAlarmType(((Number)source.get(ServiceAlarmListTable.COLUMN_ALARM_TYPE)).intValue());
        serviceAlarmList.setAlarmContent((String)source.get(ServiceAlarmListTable.COLUMN_ALARM_CONTENT));

        serviceAlarmList.setTimeBucket(((Number)source.get(ServiceAlarmListTable.COLUMN_TIME_BUCKET)).longValue());
        return serviceAlarmList;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:21,代码来源:ServiceAlarmListEsPersistenceDAO.java


注:本文中的org.elasticsearch.action.get.GetResponse.isExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。