本文整理汇总了Java中org.elasticsearch.rest.action.RestToXContentListener类的典型用法代码示例。如果您正苦于以下问题:Java RestToXContentListener类的具体用法?Java RestToXContentListener怎么用?Java RestToXContentListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RestToXContentListener类属于org.elasticsearch.rest.action包,在下文中一共展示了RestToXContentListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的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));
}
示例2: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的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;
}
});
}
示例3: listTasksResponseListener
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
/**
* Standard listener for extensions of {@link ListTasksResponse} that supports {@code group_by=nodes}.
*/
public static <T extends ListTasksResponse> ActionListener<T> listTasksResponseListener(
Supplier<DiscoveryNodes> nodesInCluster,
String groupBy,
final RestChannel channel) {
if ("nodes".equals(groupBy)) {
return new RestBuilderListener<T>(channel) {
@Override
public RestResponse buildResponse(T response, XContentBuilder builder) throws Exception {
builder.startObject();
response.toXContentGroupedByNode(builder, channel.request(), nodesInCluster.get());
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
};
} else if ("parents".equals(groupBy)) {
return new RestToXContentListener<>(channel);
} else {
throw new IllegalArgumentException("[group_by] must be one of [nodes] or [parents] but was [" + groupBy + "]");
}
}
示例4: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的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));
}
示例5: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
// Creates the render template request
SearchScriptTemplateRequest renderRequest;
try (XContentParser parser = request.contentOrSourceParamParser()) {
renderRequest = RestSearchScriptTemplateAction.parse(parser);
}
renderRequest.setSimulate(true);
final String id = request.param("id");
if (id != null) {
renderRequest.setScriptType(ScriptType.STORED);
renderRequest.setScript(id);
}
return channel -> client.execute(SearchScriptTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
示例6: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (request.hasContentOrSourceParam() == false) {
throw new ElasticsearchException("request body is required");
}
MultiSearchTemplateRequest multiRequest = parseRequest(request, allowExplicitIndex);
return channel -> client.execute(MultiSearchTemplateAction.INSTANCE, multiRequest, new RestToXContentListener<>(channel));
}
示例7: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));
request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, null));
rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false));
rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout()));
rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout()));
rolloverIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
return channel -> client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestToXContentListener<>(channel));
}
示例8: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index"));
try (XContentParser parser = request.contentOrSourceParamParser()) {
buildFromContent(parser, analyzeRequest);
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse request body", e);
}
return channel -> client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<>(channel));
}
示例9: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RestoreSnapshotRequest restoreSnapshotRequest = restoreSnapshotRequest(request.param("repository"), request.param("snapshot"));
restoreSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", restoreSnapshotRequest.masterNodeTimeout()));
restoreSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
request.applyContentParser(p -> restoreSnapshotRequest.source(p.mapOrdered()));
return channel -> client.admin().cluster().restoreSnapshot(restoreSnapshotRequest, new RestToXContentListener<>(channel));
}
示例10: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String repository = request.param("repository");
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<>(channel));
}
示例11: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
TaskId taskId = new TaskId(request.param("taskId"));
boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
TimeValue timeout = request.paramAsTime("timeout", null);
GetTaskRequest getTaskRequest = new GetTaskRequest();
getTaskRequest.setTaskId(taskId);
getTaskRequest.setWaitForCompletion(waitForCompletion);
getTaskRequest.setTimeout(timeout);
return channel -> client.admin().cluster().getTask(getTaskRequest, new RestToXContentListener<>(channel));
}
示例12: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String repository = request.param("repository", "_all");
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
snapshots = Strings.EMPTY_ARRAY;
}
SnapshotsStatusRequest snapshotsStatusRequest = snapshotsStatusRequest(repository).snapshots(snapshots);
snapshotsStatusRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", snapshotsStatusRequest.ignoreUnavailable()));
snapshotsStatusRequest.masterNodeTimeout(request.paramAsTime("master_timeout", snapshotsStatusRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().snapshotsStatus(snapshotsStatusRequest, new RestToXContentListener<>(channel));
}
示例13: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
VerifyRepositoryRequest verifyRepositoryRequest = verifyRepositoryRequest(request.param("repository"));
verifyRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", verifyRepositoryRequest.masterNodeTimeout()));
verifyRepositoryRequest.timeout(request.paramAsTime("timeout", verifyRepositoryRequest.timeout()));
return channel -> client.admin().cluster().verifyRepository(verifyRepositoryRequest, new RestToXContentListener<>(channel));
}
示例14: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot"));
request.applyContentParser(p -> createSnapshotRequest.source(p.mapOrdered()));
createSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createSnapshotRequest.masterNodeTimeout()));
createSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
return channel -> client.admin().cluster().createSnapshot(createSnapshotRequest, new RestToXContentListener<>(channel));
}
示例15: prepareRequest
import org.elasticsearch.rest.action.RestToXContentListener; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("master_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
return channel -> client.admin().cluster().pendingClusterTasks(pendingClusterTasksRequest, new RestToXContentListener<>(channel));
}