本文整理汇总了Java中org.elasticsearch.action.get.GetResponse.isSourceEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java GetResponse.isSourceEmpty方法的具体用法?Java GetResponse.isSourceEmpty怎么用?Java GetResponse.isSourceEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.get.GetResponse
的用法示例。
在下文中一共展示了GetResponse.isSourceEmpty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFragment
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public Trace getFragment(String tenantId, String id) {
Trace ret = null;
GetResponse response = client.getClient().prepareGet(
client.getIndex(tenantId), TRACE_TYPE, id).setRouting(id)
.execute()
.actionGet();
if (!response.isSourceEmpty()) {
try {
ret = mapper.readValue(response.getSourceAsString(), Trace.class);
} catch (Exception e) {
msgLog.errorFailedToParse(e);
}
}
if (msgLog.isTraceEnabled()) {
msgLog.tracef("Get fragment with id[%s] is: %s", id, ret);
}
return ret;
}
示例2: loadExistingDocumentHistory
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的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: getDocumentById
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public <T extends Indexable> T getDocumentById(String id, String index, String type, Class<T> clazz) throws ArchiveException {
try {
GetResponse response = client.prepareGet(index, type, id)
.execute()
.actionGet();
if (!response.isExists()) {
log.log(Level.WARNING, "Can't get document with id: " + id + ". Document doesn't exists.");
return null;
}
if (response.isSourceEmpty()) {
log.log(Level.WARNING, "Can't get document with id: " + id + ". Elastic returned empty source.");
return null;
}
T document = gson.fromJson(response.getSourceAsString(), clazz);
document.setDocumentId(response.getId());
return document;
} catch (Exception ex) {
log.log(Level.SEVERE, "Getting document by id from elastic failed: " + ex.getMessage());
ex.printStackTrace();
throw new ArchiveException("Getting object by id failed", ex);
}
}
示例4: getLastTick
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/** get the last tick from ES */
public Tick getLastTick() {
LOG.debug("Fetching last tick");
GetResponse get = client //
.prepareGet(index, type, id) //
.get();
if (get.isSourceEmpty()) {
return null;
}
byte[] bytes = get.getSourceAsBytes();
try {
return MAPPER.readValue(bytes, Tick.class);
}
catch (IOException e) {
return null;
}
}
示例5: queryForObject
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
* 按id读取.
* http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html
* @param id
* @param clzz
* @return
*/
public <T> T queryForObject(Class<T> clzz, String id) throws SearchException {
String typeName = this.getTypeNameFromClass(clzz);
Timer.Context timer = searchMetrics.indexTimer(typeName, "queryForObject");
try {
GetResponse response = client.prepareGet(indexName, typeName, id)
.execute().actionGet();
searchMetrics.indexIncr(typeName, "queryForObject");
if(response.isSourceEmpty()){
return null;
}
if(response.isExists()){
return null;
}
T o = this.docMapper.asObject(clzz, response.getSourceAsString());
return o;
} catch (Exception e) {
searchMetrics.failedIncr(typeName, "queryForObject", e);
logger.error("queryForObject Error. ", e);
throw new SearchException("queryForObject Error. typeName="+typeName+", id="+id, e);
}finally {
timer.stop();
}
}
示例6: doRewrite
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
if (document != null) {
return this;
}
GetRequest getRequest = new GetRequest(indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
getRequest.preference("_local");
getRequest.routing(indexedDocumentRouting);
getRequest.preference(indexedDocumentPreference);
if (indexedDocumentVersion != null) {
getRequest.version(indexedDocumentVersion);
}
GetResponse getResponse = queryShardContext.getClient().get(getRequest).actionGet();
if (getResponse.isExists() == false) {
throw new ResourceNotFoundException(
"indexed document [{}/{}/{}] couldn't be found", indexedDocumentIndex, indexedDocumentType, indexedDocumentId
);
}
if(getResponse.isSourceEmpty()) {
throw new IllegalArgumentException(
"indexed document [" + indexedDocumentIndex + "/" + indexedDocumentType + "/" + indexedDocumentId + "] source disabled"
);
}
final BytesReference source = getResponse.getSourceAsBytesRef();
return new PercolateQueryBuilder(field, documentType, source, XContentFactory.xContentType(source));
}
示例7: fetch
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
* Fetches the Shape with the given ID in the given type and index.
*
* @param getRequest
* GetRequest containing index, type and id
* @param path
* Name or path of the field in the Shape Document where the
* Shape itself is located
* @return Shape with the given ID
* @throws IOException
* Can be thrown while parsing the Shape Document and extracting
* the Shape
*/
private ShapeBuilder fetch(Client client, GetRequest getRequest, String path) throws IOException {
if (ShapesAvailability.JTS_AVAILABLE == false) {
throw new IllegalStateException("JTS not available");
}
getRequest.preference("_local");
getRequest.operationThreaded(false);
GetResponse response = client.get(getRequest).actionGet();
if (!response.isExists()) {
throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found");
}
if (response.isSourceEmpty()) {
throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() +
"] source disabled");
}
String[] pathElements = path.split("\\.");
int currentPathSlot = 0;
// It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, response.getSourceAsBytesRef())) {
XContentParser.Token currentToken;
while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (currentToken == XContentParser.Token.FIELD_NAME) {
if (pathElements[currentPathSlot].equals(parser.currentName())) {
parser.nextToken();
if (++currentPathSlot == pathElements.length) {
return ShapeBuilder.parse(parser);
}
} else {
parser.nextToken();
parser.skipChildren();
}
}
}
throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
}
}
示例8: fetch
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private List<Object> fetch(TermsLookup termsLookup, Client client) {
List<Object> terms = new ArrayList<>();
GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id())
.preference("_local").routing(termsLookup.routing());
final GetResponse getResponse = client.get(getRequest).actionGet();
if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists
List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
terms.addAll(extractedValues);
}
return terms;
}
示例9: onGetFinishedTaskFromIndex
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
* Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if
* that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster.
*/
void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException {
if (false == response.isExists()) {
listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId()));
return;
}
if (response.isSourceEmpty()) {
listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
return;
}
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
TaskResult result = TaskResult.PARSER.apply(parser, null);
listener.onResponse(new GetTaskResponse(result));
}
}
示例10: findAll
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<T> findAll(final List<String> ids) {
if (ids.isEmpty()) {
return ImmutableList.of();
}
final Builder<T> builder = ImmutableList.builder();
final MultiGetResponse response = client
.prepareMultiGet()
.add(index, type, ids)
.execute()
.actionGet();
for(final MultiGetItemResponse item : response.getResponses()) {
final GetResponse get = item.getResponse();
if(get.isSourceEmpty()) {
continue;
}
final String json = get.getSourceAsString();
final T entity = deserializer.apply(json);
builder.add((T) entity.withId(get.getId()));
}
return builder.build();
}
示例11: retrieveFile
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private static boolean retrieveFile(final Client tc, final String filepath, final String index, final String _id, final boolean legacy) {
String type = "sg";
String id = _id;
if(legacy) {
type = _id;
id = "0";
}
System.out.println("Will retrieve '"+type+"/" +id+"' into "+filepath+" "+(legacy?"(legacy mode)":""));
try (Writer writer = new FileWriter(filepath)) {
final GetResponse response = tc.get(new GetRequest(index).type(type).id(id).refresh(true).realtime(false)).actionGet();
if (response.isExists()) {
if(response.isSourceEmpty()) {
System.out.println(" FAIL: Configuration for '"+_id+"' failed because of empty source");
return false;
}
String yaml = convertToYaml(_id, response.getSourceAsBytesRef(), true);
writer.write(yaml);
System.out.println(" SUCC: Configuration for '"+_id+"' stored in "+filepath);
return true;
} else {
System.out.println(" FAIL: Get configuration for '"+_id+"' because it does not exist");
}
} catch (Exception e) {
System.out.println(" FAIL: Get configuration for '"+_id+"' failed because of "+e.toString());
}
return false;
}
示例12: get
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public <A> A get(String id, Class<A> clazz) {
IndexInfo indexInfo = getIndexInfo(clazz);
GetResponse response = elasticSearchClient.prepareGet(indexInfo.getName(), indexInfo.getType(), id).execute().actionGet();
if (response.isSourceEmpty()) {
String msg = String.format("Object (id: %s) of the type %s was not found in index %s!", id, indexInfo.getName(), indexInfo.getType());
logger.warn(msg);
return null;
}
return new Gson().fromJson(response.getSourceAsString(), clazz);
}
示例13: getRiverState
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public synchronized State getRiverState(final Folder folder) throws MessagingException {
try {
waitForCluster();
if (client.admin().indices().prepareExists(index()).execute().actionGet().isExists()) {
final GetResponse response = client
.prepareGet(index(), RIVERSTATE_TYPE, FOLDERSTATE_ID + "_" + folder.getURLName().toString().hashCode()).execute()
.get();
if (!response.isSourceEmpty()) {
return mapper.readValue(response.getSourceAsString(), new TypeReference<State>() {
});
}
}
} catch (final Exception ex) {
throw new MessagingException("Unable to get river state", ex);
}
final State rs = new State();
rs.setFolderUrl(folder.getURLName().toString());
// rs.setLastUid(1L);
rs.setExists(true);
return rs;
}
示例14: getTransaction
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public TransactionConfig getTransaction(String tenantId, String name) {
TransactionConfig ret = null;
if (msgLog.isTraceEnabled()) {
msgLog.tracef("Get transaction config with name[%s]", name);
}
try {
String index = client.getIndex(tenantId);
RefreshRequestBuilder refreshRequestBuilder =
client.getClient().admin().indices().prepareRefresh(index);
client.getClient().admin().indices().refresh(refreshRequestBuilder.request()).actionGet();
// First check if an invalid config exists
GetResponse response = client.getClient().prepareGet(
index, TXN_CONFIG_INVALID_TYPE, name).setRouting(name)
.execute()
.actionGet();
if (response.isSourceEmpty()) {
// Retrieve the valid configuration
response = client.getClient().prepareGet(
index, TXN_CONFIG_TYPE, name).setRouting(name)
.execute()
.actionGet();
}
if (!response.isSourceEmpty()) {
try {
ret = mapper.readValue(response.getSourceAsString(), TransactionConfig.class);
// Check if config was deleted
if (ret.isDeleted()) {
ret = null;
}
} catch (Exception e) {
msgLog.errorFailedToParse(e);
}
}
} catch (org.elasticsearch.indices.IndexMissingException t) {
// Ignore, as means that no transaction configurations have
// been stored yet
if (msgLog.isTraceEnabled()) {
msgLog.tracef("No index found, so unable to retrieve transaction config [%s]", name);
}
}
if (msgLog.isTraceEnabled()) {
msgLog.tracef("Get transaction config with name[%s] is: %s", name, ret);
}
return ret;
}