use of org.opensearch.action.get.GetRequest in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method fetchEntity.
private EntityBuilder fetchEntity(final String docType, final String val, final PropertyInfoIndex... index) throws CalFacadeException {
requireDocType(docType);
try {
fetchStart();
if ((!docType.equals(docTypeCollection) && !docType.equals(docTypeEvent)) && (index.length == 1) && (index[0] == PropertyInfoIndex.HREF)) {
// This path avoids the tombstone check.
final GetRequest req = new GetRequest(targetIndex, val);
final GetResponse gr = getClient().get(req, RequestOptions.DEFAULT);
if (!gr.isExists()) {
return null;
}
return getEntityBuilder(gr.getSourceAsMap());
}
final SearchHit hit = fetchEntity(docType, getFilters(null).singleEntityQuery(val, index));
if (hit == null) {
return null;
}
return getEntityBuilder(hit.getSourceAsMap());
} catch (final IOException ie) {
throw new CalFacadeException(ie);
} finally {
fetchEnd();
}
}
use of org.opensearch.action.get.GetRequest in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method currentChangeToken.
@Override
public String currentChangeToken() {
UpdateInfo ui;
try {
final GetRequest req = new GetRequest(targetIndex, updateTrackerId).storedFields("esUpdateCount");
final GetResponse resp = getClient().get(req, RequestOptions.DEFAULT);
if (!resp.isExists()) {
return null;
}
final EntityBuilder er = getEntityBuilder(resp.getFields());
ui = er.makeUpdateInfo();
synchronized (updateInfo) {
final UpdateInfo fromTbl = updateInfo.get(targetIndex);
if ((fromTbl == null) || (fromTbl.getCount() < ui.getCount())) {
updateInfo.put(targetIndex, ui);
} else {
ui = fromTbl;
}
}
return ui.getChangeToken();
} catch (final IOException ie) {
warn("Exception getting UpdateInfo: " + ie.getLocalizedMessage());
ui = new UpdateInfo();
}
return ui.getChangeToken();
}
use of org.opensearch.action.get.GetRequest in project OpenSearch by opensearch-project.
the class RestHighLevelClientEmployeeResource method getEmployeeById.
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getEmployeeById(@PathParam("id") final Long id) throws IOException {
Objects.requireNonNull(id);
final GetResponse response = client.get(new GetRequest("megacorp", Long.toString(id)), RequestOptions.DEFAULT);
if (response.isExists()) {
final Map<String, Object> source = response.getSource();
final Employee employee = new Employee();
employee.setFirstName((String) source.get("first_name"));
employee.setLastName((String) source.get("last_name"));
employee.setAge((Integer) source.get("age"));
employee.setAbout((String) source.get("about"));
@SuppressWarnings("unchecked") final List<String> interests = (List<String>) source.get("interests");
employee.setInterests(interests);
return Response.ok(employee).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
}
use of org.opensearch.action.get.GetRequest in project OpenSearch by opensearch-project.
the class RestGetAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
GetRequest getRequest = new GetRequest(request.param("index"), request.param("id"));
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBoolean("realtime", getRequest.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] to load the field from _source");
}
final String fieldsParam = request.param("stored_fields");
if (fieldsParam != null) {
final String[] fields = Strings.splitStringByCommaToArray(fieldsParam);
if (fields != null) {
getRequest.storedFields(fields);
}
}
getRequest.version(RestActions.parseVersion(request));
getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));
getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
return channel -> client.get(getRequest, new RestToXContentListener<GetResponse>(channel) {
@Override
protected RestStatus getStatus(final GetResponse response) {
return response.isExists() ? OK : NOT_FOUND;
}
});
}
use of org.opensearch.action.get.GetRequest in project OpenSearch by opensearch-project.
the class IndicesRequestIT method testGet.
public void testGet() {
String getShardAction = GetAction.NAME + "[s]";
interceptTransportActions(getShardAction);
GetRequest getRequest = new GetRequest(randomIndexOrAlias(), "id");
internalCluster().coordOnlyNodeClient().get(getRequest).actionGet();
clearInterceptedActions();
assertSameIndices(getRequest, getShardAction);
}
Aggregations