本文整理匯總了Java中org.elasticsearch.action.index.IndexRequestBuilder.setVersion方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexRequestBuilder.setVersion方法的具體用法?Java IndexRequestBuilder.setVersion怎麽用?Java IndexRequestBuilder.setVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.index.IndexRequestBuilder
的用法示例。
在下文中一共展示了IndexRequestBuilder.setVersion方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createStreamOutput
import org.elasticsearch.action.index.IndexRequestBuilder; //導入方法依賴的package包/類
private <Response extends ActionResponse> void createStreamOutput(final ActionListener<Response> listener, final long version) {
final String oldFileId = fileId;
final Map<String, Object> source = new HashMap<>();
source.put(DOC_TYPE, FILE_ID);
source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
final IndexRequestBuilder builder = client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, FILE_ID);
if (version > 0) {
builder.setVersion(version);
} else {
builder.setCreate(true);
}
builder.setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).execute(wrap(res -> {
synchronized (this) {
if (oldFileId == null || oldFileId.equals(fileId)) {
if (streamOutput != null) {
closeStreamOutput();
}
fileId = String.format(dataFileFormat, res.getVersion());
final Path outputPath = dataPath.resolve(fileId + WORKING_EXTENTION);
if (FileAccessUtils.existsFile(outputPath)) {
finalizeDataFile();
createStreamOutput(listener, res.getVersion());
return;
}
streamOutput = AccessController.doPrivileged((PrivilegedAction<IndexingProxyStreamOutput>) () -> {
try {
return new IndexingProxyStreamOutput(Files.newOutputStream(outputPath));
} catch (final IOException e) {
throw new ElasticsearchException("Could not open " + outputPath, e);
}
});
logger.info("[Writer] Opening " + outputPath.toAbsolutePath());
}
}
listener.onResponse(null);
}, listener::onFailure));
}
示例2: launchRequestSender
import org.elasticsearch.action.index.IndexRequestBuilder; //導入方法依賴的package包/類
private void launchRequestSender(final String index, final long filePosition, final long version,
final ActionListener<Map<String, Object>> listener) {
if (logger.isDebugEnabled()) {
logger.debug("Launching RequestSender(" + index + ")");
}
final Map<String, Object> source = new HashMap<>();
source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
source.put(IndexingProxyPlugin.FILE_POSITION, filePosition);
source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
source.put(DOC_TYPE, "index");
final IndexRequestBuilder builder =
client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
if (version > 0) {
builder.setVersion(version);
} else {
builder.setCreate(true);
}
builder.execute(wrap(res -> {
if (res.getResult() == Result.CREATED || res.getResult() == Result.UPDATED) {
final RequestSender sender = new RequestSender(settings, client, threadPool, namedWriteableRegistry, nodeName(), dataPath,
index, dataFileFormat, docSenderMap, logger);
final RequestSender oldSender = docSenderMap.put(index, sender);
if (oldSender != null) {
oldSender.terminate();
}
threadPool.schedule(TimeValue.ZERO, Names.GENERIC, sender);
listener.onResponse(source);
} else {
listener.onFailure(new ElasticsearchException("Failed to update .idxproxy index: " + res));
}
}, listener::onFailure));
}