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


Java NodeClient类代码示例

本文整理汇总了Java中org.elasticsearch.client.node.NodeClient的典型用法代码示例。如果您正苦于以下问题:Java NodeClient类的具体用法?Java NodeClient怎么用?Java NodeClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    if (request.hasContentOrSourceParam() == false) {
        throw new ElasticsearchException("request body is required");
    }

    // Creates the search request with all required params
    SearchRequest searchRequest = new SearchRequest();
    RestSearchAction.parseSearchRequest(searchRequest, request, null);

    // Creates the search template request
    SearchTemplateRequest searchTemplateRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        searchTemplateRequest = PARSER.parse(parser, new SearchTemplateRequest(), null);
    }
    searchTemplateRequest.setRequest(searchRequest);

    return channel -> client.execute(SearchTemplateAction.INSTANCE, searchTemplateRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RestSearchTemplateAction.java

示例2: sqlToEsQuery

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
public static String sqlToEsQuery(String sql) throws Exception {
        Map actions = new HashMap();
        Settings settings = Settings.builder().build();
//        Client client = new NodeClient(settings, null, null, actions);
//        Settings.builder()
//                .put(ThreadContext.PREFIX + ".key1", "val1")
//                .put(ThreadContext.PREFIX + ".key2", "val 2")
//                .build();

        ThreadPool threadPool = new ThreadPool(settings);
        Client client = new NodeClient(settings, threadPool);
        SearchDao searchDao = new org.nlpcn.es4sql.SearchDao(client);
        try {
            return searchDao.explain(sql).explain().explain();
        } catch (Exception e) {
            throw e;
        }
    }
 
开发者ID:mazhou,项目名称:es-sql,代码行数:19,代码来源:Test.java

示例3: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    // Creates the render template request
    SearchTemplateRequest renderRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        renderRequest = RestSearchTemplateAction.parse(parser);
    }
    renderRequest.setSimulate(true);

    String id = request.param("id");
    if (id != null) {
        renderRequest.setScriptType(ScriptType.STORED);
        renderRequest.setScript(id);
    }

    return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestRenderSearchTemplateAction.java

示例4: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
    deleteRequest.routing(request.param("routing"));
    deleteRequest.parent(request.param("parent"));
    deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
    deleteRequest.setRefreshPolicy(request.param("refresh"));
    deleteRequest.version(RestActions.parseVersion(request));
    deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        deleteRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }

    return channel -> client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestDeleteAction.java

示例5: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    String fieldsParam = request.param("fields");
    String defaultPipeline = request.param("pipeline");
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
        request.getXContentType());

    // short circuit the call to the transport layer
    return channel -> {
        BulkRestBuilderListener listener = new BulkRestBuilderListener(channel, request);
        listener.onResponse(bulkRequest);
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestNoopBulkAction.java

示例6: handleRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
    // prepare the request for execution; has the side effect of touching the request parameters
    final RestChannelConsumer action = prepareRequest(request, client);

    // validate unconsumed params, but we must exclude params used to format the response
    // use a sorted set so the unconsumed parameters appear in a reliable sorted order
    final SortedSet<String> unconsumedParams =
        request.unconsumedParams().stream().filter(p -> !responseParams().contains(p)).collect(Collectors.toCollection(TreeSet::new));

    // validate the non-response params
    if (!unconsumedParams.isEmpty()) {
        final Set<String> candidateParams = new HashSet<>();
        candidateParams.addAll(request.consumedParams());
        candidateParams.addAll(responseParams());
        throw new IllegalArgumentException(unrecognized(request, unconsumedParams, candidateParams, "parameter"));
    }

    // execute the action
    action.accept(channel);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:BaseRestHandler.java

示例7: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
    if (request.hasContent()) {
        createIndexRequest.source(request.content(), request.getXContentType());
    }
    createIndexRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false));
    createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout()));
    createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout()));
    createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
    return channel -> client.admin().indices().create(createIndexRequest, new AcknowledgedRestListener<CreateIndexResponse>(channel) {
        @Override
        public void addCustomFields(XContentBuilder builder, CreateIndexResponse response) throws IOException {
            response.addCustomFields(builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestCreateIndexAction.java

示例8: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    flushRequest.indicesOptions(IndicesOptions.fromRequest(request, flushRequest.indicesOptions()));
    flushRequest.force(request.paramAsBoolean("force", flushRequest.force()));
    flushRequest.waitIfOngoing(request.paramAsBoolean("wait_if_ongoing", flushRequest.waitIfOngoing()));
    return channel -> client.admin().indices().flush(flushRequest, new RestBuilderListener<FlushResponse>(channel) {
        @Override
        public RestResponse buildResponse(FlushResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestFlushAction.java

示例9: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
    if (request.hasParam("template")) {
        DEPRECATION_LOGGER.deprecated("Deprecated parameter[template] used, replaced by [index_patterns]");
        putRequest.patterns(Collections.singletonList(request.param("template")));
    } else {
        putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY)));
    }
    putRequest.order(request.paramAsInt("order", putRequest.order()));
    putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
    putRequest.create(request.paramAsBoolean("create", false));
    putRequest.cause(request.param("cause", ""));
    putRequest.source(request.content(), request.getXContentType());
    return channel -> client.admin().indices().putTemplate(putRequest, new AcknowledgedRestListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestPutIndexTemplateAction.java

示例10: InternalClusterInfoService

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
public InternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
    super(settings);
    this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
    this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
    this.shardRoutingToDataPath = ImmutableOpenMap.of();
    this.shardSizes = ImmutableOpenMap.of();
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    this.client = client;
    this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
    this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
    this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
    clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
    clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);

    // Add InternalClusterInfoService to listen for Master changes
    this.clusterService.addLocalNodeMasterListener(this);
    // Add to listen for state changes (when nodes are added)
    this.clusterService.addListener(this);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:InternalClusterInfoService.java

示例11: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] names = Strings.splitStringByCommaToArray(request.param("name"));

    final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
    getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
    getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));

    final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;

    return channel ->
            client.admin()
                    .indices()
                    .getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {
                        @Override
                        protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
                            final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
                            return (templateExists || implicitAll) ? OK : NOT_FOUND;
                        }
                    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RestGetIndexTemplateAction.java

示例12: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    return channel -> client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
        @Override
        public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestForceMergeAction.java

示例13: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    if (request.param("target") == null) {
        throw new IllegalArgumentException("no target index");
    }
    if (request.param("index") == null) {
        throw new IllegalArgumentException("no source index");
    }
    ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index"));
    request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, null));
    shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout()));
    shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout()));
    shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
    return channel -> client.admin().indices().shrinkIndex(shrinkIndexRequest, new AcknowledgedRestListener<ShrinkResponse>(channel) {
        @Override
        public void addCustomFields(XContentBuilder builder, ShrinkResponse response) throws IOException {
            response.addCustomFields(builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RestShrinkIndexAction.java

示例14: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

    final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
    recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
    recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));

    return channel -> client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener<RecoveryResponse>(channel) {
        @Override
        public RestResponse buildResponse(RecoveryResponse response, XContentBuilder builder) throws Exception {
            response.detailed(recoveryRequest.detailed());
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RestRecoveryAction.java

示例15: prepareRequest

import org.elasticsearch.client.node.NodeClient; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(
            Strings.splitStringByCommaToArray(request.param("index")));
    clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions()));
    fromRequest(request, clearIndicesCacheRequest);
    return channel ->
            client.admin().indices().clearCache(clearIndicesCacheRequest, new RestBuilderListener<ClearIndicesCacheResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClearIndicesCacheResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestClearIndicesCacheAction.java


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