本文整理汇总了Java中org.elasticsearch.action.get.GetRequest.type方法的典型用法代码示例。如果您正苦于以下问题:Java GetRequest.type方法的具体用法?Java GetRequest.type怎么用?Java GetRequest.type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.get.GetRequest
的用法示例。
在下文中一共展示了GetRequest.type方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetch
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
/**
* Fetches the Shape with the given ID in the given type and index.
*
* @param getRequest
* GetRequest containing index, type and id
* @param path
* Name or path of the field in the Shape Document where the
* Shape itself is located
* @return Shape with the given ID
* @throws IOException
* Can be thrown while parsing the Shape Document and extracting
* the Shape
*/
private ShapeBuilder fetch(Client client, GetRequest getRequest, String path) throws IOException {
if (ShapesAvailability.JTS_AVAILABLE == false) {
throw new IllegalStateException("JTS not available");
}
getRequest.preference("_local");
getRequest.operationThreaded(false);
GetResponse response = client.get(getRequest).actionGet();
if (!response.isExists()) {
throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found");
}
if (response.isSourceEmpty()) {
throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() +
"] source disabled");
}
String[] pathElements = path.split("\\.");
int currentPathSlot = 0;
// It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, response.getSourceAsBytesRef())) {
XContentParser.Token currentToken;
while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (currentToken == XContentParser.Token.FIELD_NAME) {
if (pathElements[currentPathSlot].equals(parser.currentName())) {
parser.nextToken();
if (++currentPathSlot == pathElements.length) {
return ShapeBuilder.parse(parser);
}
} else {
parser.nextToken();
parser.skipChildren();
}
}
}
throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
}
}
示例2: executeGet
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
@Override
public GetResponse executeGet(GetRequest getRequest) {
String json;
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.array(termsPath, randomTerms.toArray(new Object[randomTerms.size()]));
builder.endObject();
json = builder.string();
} catch (IOException ex) {
throw new ElasticsearchException("boom", ex);
}
return new GetResponse(new GetResult(getRequest.index(), getRequest.type(), getRequest.id(), 0, true, new BytesArray(json), null));
}
示例3: fetch
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
/**
* Fetches the Shape with the given ID in the given type and index.
*
* @param getRequest GetRequest containing index, type and id
* @param path Name or path of the field in the Shape Document where the Shape itself is located
* @return Shape with the given ID
* @throws IOException Can be thrown while parsing the Shape Document and extracting the Shape
*/
public ShapeBuilder fetch(GetRequest getRequest,String path) throws IOException {
getRequest.preference("_local");
getRequest.operationThreaded(false);
GetResponse response = client.get(getRequest).actionGet();
if (!response.isExists()) {
throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found");
}
String[] pathElements = Strings.splitStringToArray(path, '.');
int currentPathSlot = 0;
XContentParser parser = null;
try {
parser = XContentHelper.createParser(response.getSourceAsBytesRef());
XContentParser.Token currentToken;
while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (currentToken == XContentParser.Token.FIELD_NAME) {
if (pathElements[currentPathSlot].equals(parser.currentName())) {
parser.nextToken();
if (++currentPathSlot == pathElements.length) {
return ShapeBuilder.parse(parser);
}
} else {
parser.nextToken();
parser.skipChildren();
}
}
}
throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
} finally {
if (parser != null) {
parser.close();
}
}
}
示例4: getByMtdKeyForOnlyOneType
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
/**
* Simple and light request.
*/
public static Container getByMtdKeyForOnlyOneType(String mtd_key, String type) throws NullPointerException {
if (mtd_key == null) {
throw new NullPointerException("\"mtd_key\" can't to be null");
}
if (type == null) {
throw new NullPointerException("\"type\" can't to be null");
}
if (declared_entries_type.containsKey(type) == false) {
throw new NullPointerException("Can't found type: " + type);
}
GetRequest request = new GetRequest(ES_INDEX);
request.type(type);
request.id(mtd_key);
GetResponse getresponse = Elasticsearch.get(request);
if (getresponse.isExists() == false) {
return null;
}
ContainerEntry element = MyDMAM.gson_kit.getGson().fromJson(getresponse.getSourceAsString(), declared_entries_type.get(type));
if (element instanceof EntryRenderer) {
((EntryRenderer) element).setESType(type);
}
Container result = new Container(mtd_key, element.getOrigin());
result.addEntry(element);
return result;
}
示例5: execute
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
public void execute(PercolateRequest request, final ActionListener<PercolateResponse> listener) {
logger.debug("percolate request {}", request);
// percolate_format does not exist in PercolateRequest, only in REST API
RequestUriBuilder uriBuilder;
GetRequest getRequest = request.getRequest();
try {
if (getRequest != null) {
if (getRequest.id() != null) {
uriBuilder = new RequestUriBuilder(getRequest.index(), getRequest.type(), getRequest.id());
} else {
uriBuilder = new RequestUriBuilder(getRequest.index(), getRequest.type());
}
} else {
uriBuilder = new RequestUriBuilder(HttpRequestUtils.indicesOrAll(request), request.documentType());
}
if (request.onlyCount()) {
uriBuilder.addEndpoint("/_percolate/count");
} else {
uriBuilder.addEndpoint("/_percolate");
}
if (getRequest != null) {
uriBuilder.addQueryParameterIfNotNull("routing", getRequest.routing());
uriBuilder.addQueryParameterIfNotNull("preference", getRequest.preference());
if (getRequest.version() != Versions.MATCH_ANY) {
uriBuilder.addQueryParameter("version", getRequest.version());
}
// percolating an existing doc
uriBuilder.addQueryParameterIfNotNull("percolate_routing", request.routing());
uriBuilder.addQueryParameterIfNotNull("percolate_preference", request.preference());
uriBuilder.addQueryParameterArrayAsCommaDelimitedIfNotNullNorEmpty("percolate_index", request.indices());
uriBuilder.addQueryParameterIfNotNull("percolate_type", request.documentType());
} else {
// params does not have the same meaning in percolate_doc and percolate_existing_doc
uriBuilder.addQueryParameterIfNotNull("routing", request.routing());
uriBuilder.addQueryParameterIfNotNull("preference", request.preference());
uriBuilder.addQueryParameterIfNotNull("type", request.documentType());
}
uriBuilder.addIndicesOptions(request);
uriBuilder.addQueryParameter("pretty", true);
HttpClientRequest<ByteBuf> httpRequest = HttpClientRequest.createGet(uriBuilder.toString());
if (request.source() != null) {
httpRequest.withContent(request.source().toBytes());
}
httpClient.getHttpClient().submit(httpRequest)
.flatMap(ErrorHandler.AS_FUNC)
.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<PercolateResponse>>() {
@Override
public Observable<PercolateResponse> call(final HttpClientResponse<ByteBuf> response) {
return response.getContent().flatMap(new Func1<ByteBuf, Observable<PercolateResponse>>() {
@Override
public Observable<PercolateResponse> call(ByteBuf byteBuf) {
return PercolateResponse.parse(byteBuf);
}
});
}
})
.single()
.subscribe(new ListenerCompleterObserver<>(listener));
} catch (Exception e) {
listener.onFailure(e);
}
}
示例6: execute
import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
public void execute(final GetRequest request, final ActionListener<GetResponse> listener) {
logger.debug("get request {}", request);
try {
// encode to handle the case where the id got a space/special char
RequestUriBuilder uriBuilder = new RequestUriBuilder(request.index(), request.type(), URLEncoder.encode(request.id(), Charsets.UTF_8.displayName()));
uriBuilder.addIndicesOptions(request);
FetchSourceContext fetchSourceContext = request.fetchSourceContext();
if (fetchSourceContext != null) {
uriBuilder.addQueryParameter("_source", fetchSourceContext.fetchSource());
if (fetchSourceContext.transformSource()) {
uriBuilder.addQueryParameter("_source_transform", true);
}
// excludes & includes defaults to empty String array
if (fetchSourceContext.excludes().length > 0) {
uriBuilder.addQueryParameterArrayAsCommaDelimited("_source_exclude", fetchSourceContext.excludes());
}
if (fetchSourceContext.includes().length > 0) {
uriBuilder.addQueryParameterArrayAsCommaDelimited("_source_include", fetchSourceContext.includes());
}
}
if (request.version() != Versions.MATCH_ANY) {
uriBuilder.addQueryParameter("version", request.version());
uriBuilder.addQueryParameter("version_type", request.versionType().toString().toLowerCase());
}
if (request.fields() != null) {
uriBuilder.addQueryParameterArrayAsCommaDelimited("fields", request.fields());
}
uriBuilder.addQueryParameterIfNotNull("routing", request.routing());
uriBuilder.addQueryParameterIfNotNull("preference", request.preference());
if (request.refresh()) {
uriBuilder.addQueryParameter("refresh", request.refresh());
}
if (request.realtime()) {
uriBuilder.addQueryParameter("realtime", request.realtime());
}
httpClient.getHttpClient().submit(HttpClientRequest.createGet(uriBuilder.toString()))
.flatMap(ErrorHandler.AS_FUNC)
.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<GetResponse>>() {
@Override
public Observable<GetResponse> call(HttpClientResponse<ByteBuf> response) {
return response.getContent().flatMap(new Func1<ByteBuf, Observable<GetResponse>>() {
@Override
public Observable<GetResponse> call(ByteBuf byteBuf) {
return GetResponse.parse(byteBuf);
}
});
}
})
.single()
.subscribe(new ListenerCompleterObserver<>(listener));
} catch (Exception e) {
listener.onFailure(e);
}
}