本文整理汇总了Java中org.elasticsearch.action.get.GetRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetRequest类的具体用法?Java GetRequest怎么用?Java GetRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetRequest类属于org.elasticsearch.action.get包,在下文中一共展示了GetRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
public String get(String workflowInstanceId, String fieldToGet) {
Object value = null;
GetRequest request = new GetRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId).storedFields(fieldToGet);
GetResponse response = client.get(request).actionGet();
Map<String, GetField> fields = response.getFields();
if(fields == null) {
return null;
}
GetField field = fields.get(fieldToGet);
if(field != null) value = field.getValue();
if(value != null) {
return value.toString();
}
return null;
}
示例2: executeGet
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
protected GetResponse executeGet(GetRequest getRequest) {
assertThat(getRequest.index(), Matchers.equalTo(indexedDocumentIndex));
assertThat(getRequest.type(), Matchers.equalTo(indexedDocumentType));
assertThat(getRequest.id(), Matchers.equalTo(indexedDocumentId));
assertThat(getRequest.routing(), Matchers.equalTo(indexedDocumentRouting));
assertThat(getRequest.preference(), Matchers.equalTo(indexedDocumentPreference));
assertThat(getRequest.version(), Matchers.equalTo(indexedDocumentVersion));
if (indexedDocumentExists) {
return new GetResponse(
new GetResult(indexedDocumentIndex, indexedDocumentType, indexedDocumentId, 0L, true, documentSource,
Collections.emptyMap())
);
} else {
return new GetResponse(
new GetResult(indexedDocumentIndex, indexedDocumentType, indexedDocumentId, -1, false, null, Collections.emptyMap())
);
}
}
示例3: get
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
static Request get(GetRequest getRequest) {
String endpoint = endpoint(getRequest.index(), getRequest.type(), getRequest.id());
Params parameters = Params.builder();
parameters.withPreference(getRequest.preference());
parameters.withRouting(getRequest.routing());
parameters.withParent(getRequest.parent());
parameters.withRefresh(getRequest.refresh());
parameters.withRealtime(getRequest.realtime());
parameters.withStoredFields(getRequest.storedFields());
parameters.withVersion(getRequest.version());
parameters.withVersionType(getRequest.versionType());
parameters.withFetchSourceContext(getRequest.fetchSourceContext());
return new Request(HttpGet.METHOD_NAME, endpoint, parameters.getParams(), null);
}
示例4: invoke
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.equals(Client.class.getMethod("get", GetRequest.class))) {
return new PlainActionFuture<GetResponse>() {
@Override
public GetResponse get() throws InterruptedException, ExecutionException {
return delegate.executeGet((GetRequest) args[0]);
}
};
} else if (method.equals(Client.class.getMethod("multiTermVectors", MultiTermVectorsRequest.class))) {
return new PlainActionFuture<MultiTermVectorsResponse>() {
@Override
public MultiTermVectorsResponse get() throws InterruptedException, ExecutionException {
return delegate.executeMultiTermVectors((MultiTermVectorsRequest) args[0]);
}
};
} else if (method.equals(Object.class.getMethod("toString"))) {
return "MockClient";
}
throw new UnsupportedOperationException("this test can't handle calls to: " + method);
}
示例5: executeGet
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
protected GetResponse executeGet(GetRequest getRequest) {
assertThat(indexedShapeToReturn, notNullValue());
assertThat(indexedShapeId, notNullValue());
assertThat(indexedShapeType, notNullValue());
assertThat(getRequest.id(), equalTo(indexedShapeId));
assertThat(getRequest.type(), equalTo(indexedShapeType));
String expectedShapeIndex = indexedShapeIndex == null ? GeoShapeQueryBuilder.DEFAULT_SHAPE_INDEX_NAME : indexedShapeIndex;
assertThat(getRequest.index(), equalTo(expectedShapeIndex));
String expectedShapePath = indexedShapePath == null ? GeoShapeQueryBuilder.DEFAULT_SHAPE_FIELD_NAME : indexedShapePath;
String json;
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.field(expectedShapePath, indexedShapeToReturn);
builder.endObject();
json = builder.string();
} catch (IOException ex) {
throw new ElasticsearchException("boom", ex);
}
return new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(json), null));
}
示例6: getFact
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
/**
* Retrieve an indexed Fact by its UUID. Returns NULL if Fact cannot be fetched from ElasticSearch.
*
* @param id UUID of indexed Fact
* @return Indexed Fact or NULL if not available
*/
public FactDocument getFact(UUID id) {
if (id == null) return null;
GetResponse response;
try {
GetRequest request = new GetRequest(INDEX_NAME, TYPE_NAME, id.toString());
response = clientFactory.getHighLevelClient().get(request);
} catch (IOException ex) {
throw logAndExit(ex, String.format("Could not perform request to fetch Fact with id = %s.", id));
}
if (response.isExists()) {
LOGGER.info("Successfully fetched Fact with id = %s.", id);
return decodeFactDocument(id, response.getSourceAsBytes());
} else {
// Fact isn't indexed in ElasticSearch, log warning and return null.
LOGGER.warning("Could not fetch Fact with id = %s. Fact not indexed?", id);
return null;
}
}
示例7: handleRequest
import org.elasticsearch.action.get.GetRequest; //导入依赖的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));
// don't get any fields back...
getRequest.fields(Strings.EMPTY_ARRAY);
// TODO we can also just return the document size as Content-Length
client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
@Override
public RestResponse buildResponse(GetResponse response) {
if (!response.isExists()) {
return new BytesRestResponse(NOT_FOUND);
} else {
return new BytesRestResponse(OK);
}
}
});
}
示例8: parseExistingDocPercolate
import org.elasticsearch.action.get.GetRequest; //导入依赖的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);
}
示例9: getRequestBody
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Test
public void getRequestBody() throws Exception {
String prefix = createPrefix();
// given
GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
// when
String documentId = template.requestBody("direct:index",
new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId")
.source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
GetResponse response = template.requestBody("direct:get",
request.id(documentId), GetResponse.class);
// then
assertThat(response, notNullValue());
assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
}
示例10: doGetFromSearchRequest
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
protected void doGetFromSearchRequest(final GetRequest getRequest, final SearchRequest searchRequest, final ActionListener listener, final Client client) {
client.search(searchRequest, new DelegatingActionListener<SearchResponse, GetResponse>(listener) {
@Override
public GetResponse getDelegatedFromInstigator(final SearchResponse searchResponse) {
if (searchResponse.getHits().getTotalHits() <= 0) {
return new GetResponse(new GetResult(getRequest.index(), getRequest.type(), getRequest.id(), getRequest.version(), false, null,
null));
} else if (searchResponse.getHits().getTotalHits() > 1) {
throw new RuntimeException("cannot happen");
} else {
final SearchHit sh = searchResponse.getHits().getHits()[0];
return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null));
}
}
});
}
示例11: executePrimaryKeyLookupQuery
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn,
Object keyValue) {
if (keyValue == null) {
return null;
}
final String documentType = table.getName();
final String id = keyValue.toString();
final DataSetHeader header = new SimpleDataSetHeader(selectItems);
try {
return ElasticSearchUtils.createRow(getElasticSearchClient()
.get(new GetRequest(getIndexName(), documentType, id))
.getSource(), id, header);
} catch (IOException e) {
logger.warn("Could not execute ElasticSearch query", e);
throw new MetaModelException("Could not execute ElasticSearch query", e);
}
}
示例12: transform
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
public String[] transform(InputRow row) {
try {
final ElasticSearchDataContext dataContext = (ElasticSearchDataContext) _connection.getDataContext();
final Client client = dataContext.getElasticSearchClient();
final String[] result = new String[fields.length];
final String id = ConvertToStringTransformer.transformValue(row.getValue(documentId));
logger.info("Id is {}", id);
if (StringUtils.isNullOrEmpty(id)) {
return result;
}
final GetRequest request = new GetRequestBuilder(client).setId(id).setType(documentType).setFields(fields)
.setIndex(elasticsearchDatastore.getIndexName()).setOperationThreaded(false).request();
final ActionFuture<GetResponse> getFuture = client.get(request);
final GetResponse response = getFuture.actionGet();
logger.info("Response is {}", response);
if (!response.isExists()) {
return result;
}
for (int i = 0; i < fields.length; i++) {
final String field = fields[i];
final GetField valueGetter = response.getField(field);
if (valueGetter == null) {
logger.info("Document with id '{}' did not have the field '{}'", id, field);
} else {
final Object value = valueGetter.getValue();
result[i] = ConvertToStringTransformer.transformValue(value);
}
}
return result;
} catch (Exception e) {
logger.error("Exception while running the ElasticSearchDocumentIdLookupTransformer", e);
throw e;
}
}
开发者ID:datacleaner,项目名称:extension_elasticsearch,代码行数:41,代码来源:ElasticSearchDocumentIdLookupTransformer.java
示例13: doRewrite
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
if (document != null) {
return this;
}
GetRequest getRequest = new GetRequest(indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
getRequest.preference("_local");
getRequest.routing(indexedDocumentRouting);
getRequest.preference(indexedDocumentPreference);
if (indexedDocumentVersion != null) {
getRequest.version(indexedDocumentVersion);
}
GetResponse getResponse = queryShardContext.getClient().get(getRequest).actionGet();
if (getResponse.isExists() == false) {
throw new ResourceNotFoundException(
"indexed document [{}/{}/{}] couldn't be found", indexedDocumentIndex, indexedDocumentType, indexedDocumentId
);
}
if(getResponse.isSourceEmpty()) {
throw new IllegalArgumentException(
"indexed document [" + indexedDocumentIndex + "/" + indexedDocumentType + "/" + indexedDocumentId + "] source disabled"
);
}
final BytesReference source = getResponse.getSourceAsBytesRef();
return new PercolateQueryBuilder(field, documentType, source, XContentFactory.xContentType(source));
}
示例14: assertGetRequestsContainHeaders
import org.elasticsearch.action.get.GetRequest; //导入依赖的package包/类
private void assertGetRequestsContainHeaders(String index) {
List<RequestAndHeaders> getRequests = getRequests(GetRequest.class);
assertThat(getRequests, hasSize(greaterThan(0)));
for (RequestAndHeaders request : getRequests) {
if (!((GetRequest)request.request).index().equals(index)) {
continue;
}
assertRequestContainsHeader(request.request, request.headers);
}
}
示例15: 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");
}
}