本文整理汇总了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));
}