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


Java IndexRequestBuilder.setVersion方法代码示例

本文整理汇总了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));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:41,代码来源:IndexingProxyService.java

示例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));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:33,代码来源:IndexingProxyService.java


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