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


Java RestRequest类代码示例

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


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

示例1: urlParamsToQueryBuilder

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
public static QueryBuilder urlParamsToQueryBuilder(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
    }
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestActions.java

示例2: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String scrollIds = request.param("scroll_id");
    ClearScrollRequest clearRequest = new ClearScrollRequest();
    clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
    request.withContentOrSourceParamParserOrNull((xContentParser -> {
        if (xContentParser != null) {
            // NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value
            clearRequest.setScrollIds(null);
            try {
                buildFromContent(xContentParser, clearRequest);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to parse request body", e);
            }
        }
    }));

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

示例3: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的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.rest.RestRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    return channel ->
            client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {
                @Override
                public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
                    builder.startObject();
                    for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                        RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
                    }
                    builder.endObject();

                    return new BytesRestResponse(OK, builder);
                }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RestGetRepositoriesAction.java

示例5: buildTable

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
private Table buildTable(RestRequest request, GetAliasesResponse response) {
    Table table = getTableWithHeader(request);

    for (ObjectObjectCursor<String, List<AliasMetaData>> cursor : response.getAliases()) {
        String indexName = cursor.key;
        for (AliasMetaData aliasMetaData : cursor.value) {
            table.startRow();
            table.addCell(aliasMetaData.alias());
            table.addCell(indexName);
            table.addCell(aliasMetaData.filteringRequired() ? "*" : "-");
            String indexRouting = Strings.hasLength(aliasMetaData.indexRouting()) ? aliasMetaData.indexRouting() : "-";
            table.addCell(indexRouting);
            String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-";
            table.addCell(searchRouting);
            table.endRow();
        }
    }

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

示例6: buildRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
@Override
protected DeleteByQueryRequest buildRequest(RestRequest request) throws IOException {
    if (false == request.hasContent()) {
        throw new ElasticsearchException("_delete_by_query requires a request body");
    }
    /*
     * Passing the search request through DeleteByQueryRequest first allows
     * it to set its own defaults which differ from SearchRequest's
     * defaults. Then the parseInternalRequest can override them.
     */
    DeleteByQueryRequest internal = new DeleteByQueryRequest(new SearchRequest());

    Map<String, Consumer<Object>> consumers = new HashMap<>();
    consumers.put("conflicts", o -> internal.setConflicts((String) o));

    parseInternalRequest(internal, request, consumers);

    return internal;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RestDeleteByQueryAction.java

示例7: testHeadResponse

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
public void testHeadResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;

    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();
    RestRequest restRequest = new FakeRestRequest() {
        @Override
        public Method method() {
            return Method.HEAD;
        }
    };

    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());

    // the empty responses are handled in the HTTP layer so we do
    // not assert on them here
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestMainActionTests.java

示例8: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的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");
    FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
    String fieldsParam = request.param("fields");
    if (fieldsParam != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
    }
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
    String defaultPipeline = request.param("pipeline");
    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,
        defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());

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

示例9: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
    if (request.param("fields") != null) {
        throw new IllegalArgumentException("The parameter [fields] is no longer supported, " +
            "please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored");
    }
    String[] sFields = null;
    String sField = request.param("stored_fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource,
            request.param("routing"), parser, allowExplicitIndex);
    }

    return channel -> client.multiGet(multiGetRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestMultiGetAction.java

示例10: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
/**
 *@description 插件的业务处理方法
 *@time 创建时间:2017年8月31日下午4:21:52
 *@param request
 *@param client
 *@return
 *@throws IOException
 *@author dzn
 */
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client)
        throws IOException {
    LOGGER.info("My Rest Action Handler");  
    Map<String, String> params = request.params();
    LOGGER.info("Param : {}", params);
    final String actionParam = request.param("action");
    LOGGER.info("actionParam : {}", actionParam);
    RestChannelConsumer res = new RestChannelConsumer(){
        @Override
        public void accept(RestChannel channel) throws Exception {
            XContentBuilder builder = channel.newBuilder();
            builder.startObject();  
            //返回给页面的信息
            builder.field("message", "This is my first plugin");
            if(null != actionParam && actionParam.trim().length() > 0){
                builder.field("接收到参数actionParam", actionParam);
            }
            builder.endObject();  
            channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
        }
    };
    return res;
}
 
开发者ID:SnailFastGo,项目名称:elasticsearch_plugin,代码行数:34,代码来源:MyRestAction.java

示例11: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的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

示例12: doCatRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);

    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {
                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestSegmentsAction.java

示例13: parseRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
/**
 * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
 */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
    MultiSearchRequest multiRequest = new MultiSearchRequest();
    if (restRequest.hasParam("max_concurrent_searches")) {
        multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
    }

    parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
        try {
            final QueryParseContext queryParseContext = new QueryParseContext(parser);
            searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext));
            multiRequest.add(searchRequest);
        } catch (IOException e) {
            throw new ElasticsearchParseException("Exception when parsing search request", e);
        }
    });

    return multiRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RestMultiSearchAction.java

示例14: doRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的package包/类
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    CountRequest countRequest = new CountRequest(indices);
    String source = request.param("source");
    if (source != null) {
        countRequest.source(source);
    } else {
        QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
        if (querySourceBuilder != null) {
            countRequest.source(querySourceBuilder);
        }
    }

    client.search(countRequest.toSearchRequest(), new RestResponseListener<SearchResponse>(channel) {
        @Override
        public RestResponse buildResponse(SearchResponse countResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, countResponse), channel);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:RestCountAction.java

示例15: prepareRequest

import org.elasticsearch.rest.RestRequest; //导入依赖的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


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