本文整理汇总了Java中org.elasticsearch.rest.action.support.RestActions类的典型用法代码示例。如果您正苦于以下问题:Java RestActions类的具体用法?Java RestActions怎么用?Java RestActions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestActions类属于org.elasticsearch.rest.action.support包,在下文中一共展示了RestActions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
multiGetRequest.preference(request.param("preference"));
multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));
String[] sFields = null;
String sField = request.param("fields");
if (sField != null) {
sFields = Strings.splitStringByCommaToArray(sField);
}
FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), RestActions.getRestContent(request), allowExplicitIndex);
client.multiGet(multiGetRequest, new RestToXContentListener<MultiGetResponse>(channel));
}
示例2: parseExistingDocPercolate
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) {
String index = restRequest.param("index");
String type = restRequest.param("type");
percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("percolate_index", index)));
percolateRequest.documentType(restRequest.param("percolate_type", type));
GetRequest getRequest = new GetRequest(index, type,
restRequest.param("id"));
getRequest.routing(restRequest.param("routing"));
getRequest.preference(restRequest.param("preference"));
getRequest.refresh(restRequest.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.realtime(restRequest.paramAsBoolean("realtime", null));
getRequest.version(RestActions.parseVersion(restRequest));
getRequest.versionType(VersionType.fromString(restRequest.param("version_type"), getRequest.versionType()));
percolateRequest.getRequest(getRequest);
percolateRequest.routing(restRequest.param("percolate_routing"));
percolateRequest.preference(restRequest.param("percolate_preference"));
percolateRequest.source(RestActions.getRestContent(restRequest));
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
executePercolate(percolateRequest, restChannel, client);
}
示例3: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
String scrollIds = request.param("scroll_id");
ClearScrollRequest clearRequest = new ClearScrollRequest();
clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
if (RestActions.hasBodyContent(request)) {
XContentType type = RestActions.guessBodyContentType(request);
if (type == null) {
scrollIds = RestActions.getRestContent(request).toUtf8();
clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
} else {
// NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value
clearRequest.setScrollIds(null);
buildFromContent(RestActions.getRestContent(request), clearRequest);
}
}
client.clearScroll(clearRequest, new RestStatusToXContentListener<ClearScrollResponse>(channel));
}
示例4: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
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")));
}
if (RestActions.hasBodyContent(request)) {
XContentType type = XContentFactory.xContentType(RestActions.getRestContent(request));
if (type == null) {
if (scrollId == null) {
scrollId = RestActions.getRestContent(request).toUtf8();
searchScrollRequest.scrollId(scrollId);
}
} else {
// NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
buildFromContent(RestActions.getRestContent(request), searchScrollRequest);
}
}
client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}
示例5: readURIParameters
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
static public void readURIParameters(TermVectorsRequest termVectorsRequest, RestRequest request) {
String fields = request.param("fields");
addFieldStringsFromParameter(termVectorsRequest, fields);
termVectorsRequest.offsets(request.paramAsBoolean("offsets", termVectorsRequest.offsets()));
termVectorsRequest.positions(request.paramAsBoolean("positions", termVectorsRequest.positions()));
termVectorsRequest.payloads(request.paramAsBoolean("payloads", termVectorsRequest.payloads()));
termVectorsRequest.routing(request.param("routing"));
termVectorsRequest.realtime(request.paramAsBoolean("realtime", null));
termVectorsRequest.version(RestActions.parseVersion(request, termVectorsRequest.version()));
termVectorsRequest.versionType(VersionType.fromString(request.param("version_type"), termVectorsRequest.versionType()));
termVectorsRequest.parent(request.param("parent"));
termVectorsRequest.preference(request.param("preference"));
termVectorsRequest.termStatistics(request.paramAsBoolean("termStatistics", termVectorsRequest.termStatistics()));
termVectorsRequest.termStatistics(request.paramAsBoolean("term_statistics", termVectorsRequest.termStatistics()));
termVectorsRequest.fieldStatistics(request.paramAsBoolean("fieldStatistics", termVectorsRequest.fieldStatistics()));
termVectorsRequest.fieldStatistics(request.paramAsBoolean("field_statistics", termVectorsRequest.fieldStatistics()));
termVectorsRequest.dfs(request.paramAsBoolean("dfs", termVectorsRequest.dfs()));
}
示例6: doRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的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);
}
});
}
示例7: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
final ExistsRequest existsRequest = new ExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
existsRequest.indicesOptions(IndicesOptions.fromRequest(request, existsRequest.indicesOptions()));
if (RestActions.hasBodyContent(request)) {
existsRequest.source(RestActions.getRestContent(request));
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
existsRequest.source(querySourceBuilder);
}
}
existsRequest.routing(request.param("routing"));
existsRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
existsRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
existsRequest.preference(request.param("preference"));
client.exists(existsRequest, new RestBuilderListener<ExistsResponse>(channel) {
@Override
public RestResponse buildResponse(ExistsResponse response, XContentBuilder builder) throws Exception {
RestStatus status = response.exists() ? OK : NOT_FOUND;
builder.startObject();
builder.field("exists", response.exists());
builder.endObject();
return new BytesRestResponse(status, builder);
}
});
}
示例8: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
if (RestActions.hasBodyContent(request)) {
countRequest.source(RestActions.getRestContent(request));
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
countRequest.source(querySourceBuilder);
}
}
countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
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) {
countRequest.terminateAfter(terminateAfter);
}
client.search(countRequest.toSearchRequest(), 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().totalHits());
buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
response.getFailedShards(), response.getShardFailures());
builder.endObject();
return new BytesRestResponse(response.status(), builder);
}
});
}
示例9: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
String[] texts = request.paramAsStringArrayOrEmptyIfAll("text");
AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index"));
analyzeRequest.text(texts);
analyzeRequest.analyzer(request.param("analyzer"));
analyzeRequest.field(request.param("field"));
analyzeRequest.tokenizer(request.param("tokenizer"));
analyzeRequest.tokenFilters(request.paramAsStringArray("filter", request.paramAsStringArray("token_filter",
request.paramAsStringArray("token_filters", request.paramAsStringArray("filters", analyzeRequest.tokenFilters())))));
analyzeRequest.charFilters(request.paramAsStringArray("char_filter", request.paramAsStringArray("char_filters", analyzeRequest.charFilters())));
analyzeRequest.explain(request.paramAsBoolean("explain", false));
analyzeRequest.attributes(request.paramAsStringArray("attributes", analyzeRequest.attributes()));
if (RestActions.hasBodyContent(request)) {
XContentType type = RestActions.guessBodyContentType(request);
if (type == null) {
if (texts == null || texts.length == 0) {
texts = new String[]{ RestActions.getRestContent(request).toUtf8() };
analyzeRequest.text(texts);
}
} else {
// NOTE: if rest request with xcontent body has request parameters, the parameters does not override xcontent values
buildFromContent(RestActions.getRestContent(request), analyzeRequest, parseFieldMatcher);
}
}
client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<AnalyzeResponse>(channel));
}
示例10: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
if (RestActions.hasBodyContent(request) && request.hasParam("fields")) {
throw new IllegalArgumentException("can't specify a request body and [fields] request parameter, either specify a request body or the [fields] request parameter");
}
final FieldStatsRequest fieldStatsRequest = new FieldStatsRequest();
fieldStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
fieldStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, fieldStatsRequest.indicesOptions()));
fieldStatsRequest.level(request.param("level", FieldStatsRequest.DEFAULT_LEVEL));
if (RestActions.hasBodyContent(request)) {
fieldStatsRequest.source(RestActions.getRestContent(request));
} else {
fieldStatsRequest.setFields(Strings.splitStringByCommaToArray(request.param("fields")));
}
client.fieldStats(fieldStatsRequest, new RestBuilderListener<FieldStatsResponse>(channel) {
@Override
public RestResponse buildResponse(FieldStatsResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.startObject("indices");
for (Map.Entry<String, Map<String, FieldStats>> entry1 : response.getIndicesMergedFieldStats().entrySet()) {
builder.startObject(entry1.getKey());
builder.startObject("fields");
for (Map.Entry<String, FieldStats> entry2 : entry1.getValue().entrySet()) {
builder.field(entry2.getKey());
entry2.getValue().toXContent(builder, request);
}
builder.endObject();
builder.endObject();
}
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
});
}
示例11: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
getRequest.operationThreaded(true);
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing
getRequest.parent(request.param("parent"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBoolean("realtime", null));
getRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));
String sField = request.param("fields");
if (sField != null) {
String[] sFields = Strings.splitStringByCommaToArray(sField);
if (sFields != null) {
getRequest.fields(sFields);
}
}
getRequest.version(RestActions.parseVersion(request));
getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));
getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
client.get(getRequest, new RestBuilderListener<GetResponse>(channel) {
@Override
public RestResponse buildResponse(GetResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
if (!response.isExists()) {
return new BytesRestResponse(NOT_FOUND, builder);
} else {
return new BytesRestResponse(OK, builder);
}
}
});
}
示例12: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest restRequest, final RestChannel restChannel, final Client client) throws Exception {
MultiPercolateRequest multiPercolateRequest = new MultiPercolateRequest();
multiPercolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, multiPercolateRequest.indicesOptions()));
multiPercolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index")));
multiPercolateRequest.documentType(restRequest.param("type"));
multiPercolateRequest.add(RestActions.getRestContent(restRequest), allowExplicitIndex);
client.multiPercolate(multiPercolateRequest, new RestToXContentListener<MultiPercolateResponse>(restChannel));
}
示例13: parseDocPercolate
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
void parseDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) {
percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index")));
percolateRequest.documentType(restRequest.param("type"));
percolateRequest.routing(restRequest.param("routing"));
percolateRequest.preference(restRequest.param("preference"));
percolateRequest.source(RestActions.getRestContent(restRequest));
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
executePercolate(percolateRequest, restChannel, client);
}
示例14: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
deleteRequest.routing(request.param("routing"));
deleteRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
deleteRequest.refresh(request.paramAsBoolean("refresh", deleteRequest.refresh()));
deleteRequest.version(RestActions.parseVersion(request));
deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));
String consistencyLevel = request.param("consistency");
if (consistencyLevel != null) {
deleteRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
}
client.delete(deleteRequest, new RestBuilderListener<DeleteResponse>(channel) {
@Override
public RestResponse buildResponse(DeleteResponse result, XContentBuilder builder) throws Exception {
ActionWriteResponse.ShardInfo shardInfo = result.getShardInfo();
builder.startObject().field(Fields.FOUND, result.isFound())
.field(Fields._INDEX, result.getIndex())
.field(Fields._TYPE, result.getType())
.field(Fields._ID, result.getId())
.field(Fields._VERSION, result.getVersion())
.value(shardInfo)
.endObject();
RestStatus status = shardInfo.status();
if (!result.isFound()) {
status = NOT_FOUND;
}
return new BytesRestResponse(status, builder);
}
});
}
示例15: handleRequest
import org.elasticsearch.rest.action.support.RestActions; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
String[] types = Strings.splitStringByCommaToArray(request.param("type"));
String path = request.path();
boolean isTemplateRequest = isTemplateRequest(path);
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex);
client.multiSearch(multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel));
}