當前位置: 首頁>>代碼示例>>Java>>正文


Java GetRequest.id方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.get.GetRequest.id方法的典型用法代碼示例。如果您正苦於以下問題:Java GetRequest.id方法的具體用法?Java GetRequest.id怎麽用?Java GetRequest.id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.get.GetRequest的用法示例。


在下文中一共展示了GetRequest.id方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:51,代碼來源:GeoShapeQueryBuilder.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:TermsQueryBuilderTests.java

示例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();
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:44,代碼來源:ShapeFetchService.java

示例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;
}
 
開發者ID:hdsdi3g,項目名稱:MyDMAM,代碼行數:34,代碼來源:ContainerOperations.java

示例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);
    }
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:71,代碼來源:PercolateActionHandler.java


注:本文中的org.elasticsearch.action.get.GetRequest.id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。