本文整理汇总了Java中org.elasticsearch.rest.RestRequest.withContentOrSourceParamParserOrNull方法的典型用法代码示例。如果您正苦于以下问题:Java RestRequest.withContentOrSourceParamParserOrNull方法的具体用法?Java RestRequest.withContentOrSourceParamParserOrNull怎么用?Java RestRequest.withContentOrSourceParamParserOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.rest.RestRequest
的用法示例。
在下文中一共展示了RestRequest.withContentOrSourceParamParserOrNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: prepareRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String scrollId = request.param("scroll_id");
SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
searchScrollRequest.scrollId(scrollId);
String scroll = request.param("scroll");
if (scroll != null) {
searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
}
request.withContentOrSourceParamParserOrNull(xContentParser -> {
if (xContentParser != null) {
// NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
try {
buildFromContent(xContentParser, searchScrollRequest);
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse request body", e);
}
}});
return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel));
}
示例3: prepareRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
SearchRequest searchRequest = new SearchRequest();
request.withContentOrSourceParamParserOrNull(parser ->
parseSearchRequest(searchRequest, request, parser));
return channel -> client.search(searchRequest, new RestStatusToXContentListener<>(channel));
}
示例4: doCatRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
SearchRequest countRequest = new SearchRequest(indices);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
countRequest.source(searchSourceBuilder);
try {
request.withContentOrSourceParamParserOrNull(parser -> {
if (parser == null) {
QueryBuilder queryBuilder = RestActions.urlParamsToQueryBuilder(request);
if (queryBuilder != null) {
searchSourceBuilder.query(queryBuilder);
}
} else {
searchSourceBuilder.query(RestActions.getQueryContent(parser));
}
});
} catch (IOException e) {
throw new ElasticsearchException("Couldn't parse query", e);
}
return channel -> client.search(countRequest, new RestResponseListener<SearchResponse>(channel) {
@Override
public RestResponse buildResponse(SearchResponse countResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, countResponse), channel);
}
});
}
示例5: prepareRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
TermVectorsRequest template = new TermVectorsRequest();
template.index(request.param("index"));
template.type(request.param("type"));
RestTermVectorsAction.readURIParameters(template, request);
multiTermVectorsRequest.ids(Strings.commaDelimitedListToStringArray(request.param("ids")));
request.withContentOrSourceParamParserOrNull(p -> multiTermVectorsRequest.add(template, p));
return channel -> client.multiTermVectors(multiTermVectorsRequest, new RestToXContentListener<MultiTermVectorsResponse>(channel));
}
示例6: prepareRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的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);
}
});
}
};
}
示例7: prepareRequest
import org.elasticsearch.rest.RestRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
countRequest.source(searchSourceBuilder);
request.withContentOrSourceParamParserOrNull(parser -> {
if (parser == null) {
QueryBuilder queryBuilder = RestActions.urlParamsToQueryBuilder(request);
if (queryBuilder != null) {
searchSourceBuilder.query(queryBuilder);
}
} else {
searchSourceBuilder.query(RestActions.getQueryContent(parser));
}
});
countRequest.routing(request.param("routing"));
float minScore = request.paramAsFloat("min_score", -1f);
if (minScore != -1f) {
searchSourceBuilder.minScore(minScore);
}
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
countRequest.preference(request.param("preference"));
final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER);
if (terminateAfter < 0) {
throw new IllegalArgumentException("terminateAfter must be > 0");
} else if (terminateAfter > 0) {
searchSourceBuilder.terminateAfter(terminateAfter);
}
return channel -> client.search(countRequest, new RestBuilderListener<SearchResponse>(channel) {
@Override
public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
if (terminateAfter != DEFAULT_TERMINATE_AFTER) {
builder.field("terminated_early", response.isTerminatedEarly());
}
builder.field("count", response.getHits().getTotalHits());
buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
response.getFailedShards(), response.getShardFailures());
builder.endObject();
return new BytesRestResponse(response.status(), builder);
}
});
}