• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ValidateQueryRequest类的典型用法和代码示例

java 1次浏览

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

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

示例1: testSerialize

点赞 3

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
        validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
        validateQueryRequest.rewrite(true);
        validateQueryRequest.explain(false);
        validateQueryRequest.types("type1", "type2");
        ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
            new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAliases(), readRequest.filteringAliases());
            assertArrayEquals(request.types(), readRequest.types());
            assertEquals(request.explain(), readRequest.explain());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.rewrite(), readRequest.rewrite());
            assertEquals(request.shardId(), readRequest.shardId());
        }
    }
}
 

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

示例2: testSerialize50Request

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public void testSerialize50Request() throws IOException {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
    validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
    validateQueryRequest.rewrite(true);
    validateQueryRequest.explain(false);
    validateQueryRequest.types("type1", "type2");
    ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
        new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
    BytesArray requestBytes = new BytesArray(Base64.getDecoder()
        // this is a base64 encoded request generated with the same input
        .decode("AAVpbmRleAZmb29iYXIBAQdpbmRpY2VzBAR0ZXJtP4AAAAAFZmllbGQVBXZhbHVlAgV0eXBlMQV0eXBlMgIGYWxpYXMwBmFsaWFzMQABAA"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertArrayEquals(request.filteringAliases().getAliases(), readRequest.filteringAliases().getAliases());
        expectThrows(IllegalStateException.class, () -> readRequest.filteringAliases().getQueryBuilder());
        assertArrayEquals(request.types(), readRequest.types());
        assertEquals(request.explain(), readRequest.explain());
        assertEquals(request.query(), readRequest.query());
        assertEquals(request.rewrite(), readRequest.rewrite());
        assertEquals(request.shardId(), readRequest.shardId());
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
 

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

示例3: testValidateQuery

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public void testValidateQuery() {
    String validateQueryShardAction = ValidateQueryAction.NAME + "[s]";
    interceptTransportActions(validateQueryShardAction);

    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().validateQuery(validateQueryRequest).actionGet();

    clearInterceptedActions();
    assertSameIndices(validateQueryRequest, validateQueryShardAction);
}
 

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

示例4: search

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
/**
 * This is a new search that accepts additionalSearchInformation. We need it for our complex question searches.
 * We have duplicated the methods that need this parameter, like prepareSearchRequest
 */
public SearchResponse search(String searchTerms, List<String> references, List<String> siteIds, int start, int end, Map<String,String> additionalSearchInformation) {
    final Pair<SearchRequestBuilder,QueryBuilder> searchBuilders = prepareSearchRequest(searchTerms, references, siteIds, start, end, additionalSearchInformation);
    final SearchRequestBuilder searchRequestBuilder = searchBuilders.getLeft();
    final QueryBuilder queryBuilder = searchBuilders.getRight();

    getLog().debug("Search request from index builder [" + getName() + "]: " + searchRequestBuilder.toString());

    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(indexName);
    QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder().setQuery(queryBuilder);
    validateQueryRequest.source(querySourceBuilder);
    validateQueryRequest.explain(true);


    try {
        ActionFuture<ValidateQueryResponse> future = client.admin().indices().validateQuery(validateQueryRequest); // the client is org.elasticsearch.client.Client
        ValidateQueryResponse responseV = future.get(); // typical java future as response

        if (responseV.isValid()) {
            SearchResponse response = searchRequestBuilder.execute().actionGet();
            getLog().debug("Search request from index builder [" + getName() + "] took: " + response.getTook().format());
            eventTrackingService.post(eventTrackingService.newEvent(SearchService.EVENT_SEARCH,
                    SearchService.EVENT_SEARCH_REF + queryBuilder.toString(), true,
                    NotificationService.PREF_IMMEDIATE));

            return response;
        }else{
            return null;
        }
    }catch(Exception ex){
        return null;
    }

}
 

开发者ID:sakaiproject,
项目名称:sakai,
代码行数:38,
代码来源:QuestionElasticSearchIndexBuilder.java

示例5: should_not_validate

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Test
public void should_not_validate() throws Exception {
    ensureSearchable(THE_INDEX);
    ValidateQueryResponse response = httpClient.admin().indices().validateQuery(new ValidateQueryRequest(THE_INDEX).source("foo")).get();

    Assertions.assertThat(response.isValid()).isFalse();
}
 

开发者ID:obourgain,
项目名称:elasticsearch-http,
代码行数:8,
代码来源:ValidateQueryActionHandlerTest.java

示例6: toXContent

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Override
protected XContentBuilder toXContent(ValidateQueryRequest request, ValidateQueryResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field("valid", response.isValid());
    buildBroadcastShardsHeader(builder, response);

    List<? extends QueryExplanation> queryExplanation = response.getQueryExplanation();

    if (queryExplanation != null && !queryExplanation.isEmpty()) {
        builder.startArray("explanations");
        for (QueryExplanation explanation : queryExplanation) {
            builder.startObject();
            if (explanation.getIndex() != null) {
                builder.field("index", explanation.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
            }
            builder.field("valid", explanation.isValid());
            if (explanation.getError() != null) {
                builder.field("error", explanation.getError());
            }
            if (explanation.getExplanation() != null) {
                builder.field("explanation", explanation.getExplanation());
            }
            builder.endObject();
        }
        builder.endArray();
    }
    builder.endObject();
    return builder;
}
 

开发者ID:javanna,
项目名称:elasticshell,
代码行数:30,
代码来源:ValidateQueryRequestBuilder.java

示例7: validateQuery

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Override
public ActionFuture<ValidateQueryResponse> validateQuery(final ValidateQueryRequest request) {
    return execute(ValidateQueryAction.INSTANCE, request);
}
 

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

示例8: prepareRequest

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
    validateQueryRequest.explain(request.paramAsBoolean("explain", false));
    validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    validateQueryRequest.rewrite(request.paramAsBoolean("rewrite", false));

    Exception bodyParsingException = null;
    try {
        request.withContentOrSourceParamParserOrNull(parser -> {
            if (parser != null) {
                validateQueryRequest.query(RestActions.getQueryContent(parser));
            } else if (request.hasParam("q")) {
                validateQueryRequest.query(RestActions.urlParamsToQueryBuilder(request));
            }
        });
    } catch (Exception e) {
        bodyParsingException = e;
    }

    final Exception finalBodyParsingException = bodyParsingException;
    return channel -> {
        if (finalBodyParsingException != null) {
            if (finalBodyParsingException instanceof ParsingException) {
                handleException(validateQueryRequest, ((ParsingException) finalBodyParsingException).getDetailedMessage(), channel);
            } else {
                handleException(validateQueryRequest, finalBodyParsingException.getMessage(), channel);
            }
        } else {
            client.admin().indices().validateQuery(validateQueryRequest, new RestBuilderListener<ValidateQueryResponse>(channel) {
                @Override
                public RestResponse buildResponse(ValidateQueryResponse response, XContentBuilder builder) throws Exception {
                    builder.startObject();
                    builder.field(VALID_FIELD, response.isValid());
                    buildBroadcastShardsHeader(builder, request, response);
                    if (response.getQueryExplanation() != null && !response.getQueryExplanation().isEmpty()) {
                        builder.startArray(EXPLANATIONS_FIELD);
                        for (QueryExplanation explanation : response.getQueryExplanation()) {
                            builder.startObject();
                            if (explanation.getIndex() != null) {
                                builder.field(INDEX_FIELD, explanation.getIndex());
                            }
                            builder.field(VALID_FIELD, explanation.isValid());
                            if (explanation.getError() != null) {
                                builder.field(ERROR_FIELD, explanation.getError());
                            }
                            if (explanation.getExplanation() != null) {
                                builder.field(EXPLANATION_FIELD, explanation.getExplanation());
                            }
                            builder.endObject();
                        }
                        builder.endArray();
                    }
                    builder.endObject();
                    return new BytesRestResponse(OK, builder);
                }
            });
        }
    };
}
 

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

示例9: handleException

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
private void handleException(final ValidateQueryRequest request, final String message, final RestChannel channel) throws IOException {
    channel.sendResponse(buildErrorResponse(channel.newBuilder(), message, request.explain()));
}
 

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

示例10: handleRequest

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
    if (RestActions.hasBodyContent(request)) {
        validateQueryRequest.source(RestActions.getRestContent(request));
    } else {
        QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
        if (querySourceBuilder != null) {
            validateQueryRequest.source(querySourceBuilder);
        }
    }
    validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    if (request.paramAsBoolean("explain", false)) {
        validateQueryRequest.explain(true);
    } else {
        validateQueryRequest.explain(false);
    }
    if (request.paramAsBoolean("rewrite", false)) {
        validateQueryRequest.rewrite(true);
    } else {
        validateQueryRequest.rewrite(false);
    }

    client.admin().indices().validateQuery(validateQueryRequest, new RestBuilderListener<ValidateQueryResponse>(channel) {
        @Override
        public RestResponse buildResponse(ValidateQueryResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            builder.field("valid", response.isValid());

            buildBroadcastShardsHeader(builder, request, response);

            if (response.getQueryExplanation() != null && !response.getQueryExplanation().isEmpty()) {
                builder.startArray("explanations");
                for (QueryExplanation explanation : response.getQueryExplanation()) {
                    builder.startObject();
                    if (explanation.getIndex() != null) {
                        builder.field("index", explanation.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
                    }
                    builder.field("valid", explanation.isValid());
                    if (explanation.getError() != null) {
                        builder.field("error", explanation.getError());
                    }
                    if (explanation.getExplanation() != null) {
                        builder.field("explanation", explanation.getExplanation());
                    }
                    builder.endObject();
                }
                builder.endArray();
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 

开发者ID:baidu,
项目名称:Elasticsearch,
代码行数:56,
代码来源:RestValidateQueryAction.java

示例11: execute

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public void execute(ValidateQueryRequest request, final ActionListener<ValidateQueryResponse> listener) {
    logger.debug("validate query request {}", request);
    try {
        RequestUriBuilder uriBuilder;
        if (request.types() != null) {
            uriBuilder = new RequestUriBuilder(Strings.arrayToCommaDelimitedString(request.indices()), Strings.arrayToCommaDelimitedString(request.types()));
        } else {
            uriBuilder = new RequestUriBuilder(Strings.arrayToCommaDelimitedString(request.indices()));
        }
        uriBuilder.addEndpoint("/_validate/query")
                .addIndicesOptions(request);

        if (request.explain()) {
            uriBuilder.addQueryParameter("explain", "true");
        }

        HttpClientRequest<ByteBuf> httpRequest = HttpClientRequest.createPost(uriBuilder.toString());

        if (ValidateRequestAccessor.getSource(request) != null) {
            httpRequest.withContent(ValidateRequestAccessor.getSource(request).toBytes());
        }

        httpClient.getHttpClient().submit(httpRequest)
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ValidateQueryResponse>>() {
                    @Override
                    public Observable<ValidateQueryResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<ValidateQueryResponse>>() {
                            @Override
                            public Observable<ValidateQueryResponse> call(ByteBuf byteBuf) {
                                return ValidateQueryResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));

    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 

开发者ID:obourgain,
项目名称:elasticsearch-http,
代码行数:43,
代码来源:ValidateQueryActionHandler.java

示例12: validateQuery

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public void validateQuery(ValidateQueryRequest request, ActionListener<ValidateQueryResponse> listener) {
    validateQueryActionHandler.execute(request, listener);
}
 

开发者ID:obourgain,
项目名称:elasticsearch-http,
代码行数:4,
代码来源:HttpIndicesAdminClient.java

示例13: should_validate

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Test
public void should_validate() throws Exception {
    ValidateQueryResponse response = httpClient.admin().indices().validateQuery(new ValidateQueryRequest(THE_INDEX).source(new QuerySourceBuilder().setQuery(QueryBuilders.matchAllQuery()))).get();

    Assertions.assertThat(response.isValid()).isTrue();
}
 

开发者ID:obourgain,
项目名称:elasticsearch-http,
代码行数:7,
代码来源:ValidateQueryActionHandlerTest.java

示例14: ValidateQueryRequestBuilder

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
public ValidateQueryRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ValidateQueryRequest(), jsonToString, stringToJson);
}
 

开发者ID:javanna,
项目名称:elasticshell,
代码行数:4,
代码来源:ValidateQueryRequestBuilder.java

示例15: doExecute

点赞 2

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
@Override
protected ActionFuture<ValidateQueryResponse> doExecute(ValidateQueryRequest request) {
    return client.admin().indices().validateQuery(request);
}
 

开发者ID:javanna,
项目名称:elasticshell,
代码行数:5,
代码来源:ValidateQueryRequestBuilder.java

示例16: validateQuery

点赞 1

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
/**
 * Validate a query for correctness.
 *
 * @param request The count request
 * @return The result future
 */
ActionFuture<ValidateQueryResponse> validateQuery(ValidateQueryRequest request);
 

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

示例17: validateQuery

点赞 1

import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; //导入依赖的package包/类
/**
 * Validate a query for correctness.
 *
 * @param request The count request
 * @return The result future
 * @see Requests#countRequest(String...)
 */
ActionFuture<ValidateQueryResponse> validateQuery(ValidateQueryRequest request);
 

开发者ID:baidu,
项目名称:Elasticsearch,
代码行数:9,
代码来源:IndicesAdminClient.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)