Search in sources :

Example 6 with GetRequest

use of org.elasticsearch.action.get.GetRequest in project elasticsearch by elastic.

the class RestGetAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    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"));
    getRequest.parent(request.param("parent"));
    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;
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequest(org.elasticsearch.action.get.GetRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) VersionType(org.elasticsearch.index.VersionType) Strings(org.elasticsearch.common.Strings) RestActions(org.elasticsearch.rest.action.RestActions) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) RestStatus(org.elasticsearch.rest.RestStatus) GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 7 with GetRequest

use of org.elasticsearch.action.get.GetRequest in project flink by apache.

the class SourceSinkDataTestKit method verifyProducedSinkData.

/**
	 * Verify the results in an Elasticsearch index. The results must first be produced into the index
	 * using a {@link TestElasticsearchSinkFunction};
	 *
	 * @param client The client to use to connect to Elasticsearch
	 * @param index The index to check
	 */
public static void verifyProducedSinkData(Client client, String index) {
    for (int i = 0; i < NUM_ELEMENTS; i++) {
        GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet();
        Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME));
    }
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 8 with GetRequest

use of org.elasticsearch.action.get.GetRequest in project graylog2-server by Graylog2.

the class Messages method get.

public ResultMessage get(String messageId, String index) throws DocumentNotFoundException {
    final GetRequest request = c.prepareGet(index, IndexMapping.TYPE_MESSAGE, messageId).request();
    final GetResponse r = c.get(request).actionGet();
    if (!r.isExists()) {
        throw new DocumentNotFoundException(index, messageId);
    }
    return ResultMessage.parseFromSource(r);
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 9 with GetRequest

use of org.elasticsearch.action.get.GetRequest in project elasticsearch by elastic.

the class TermsQueryBuilder method fetch.

private List<Object> fetch(TermsLookup termsLookup, Client client) {
    List<Object> terms = new ArrayList<>();
    GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id()).preference("_local").routing(termsLookup.routing());
    final GetResponse getResponse = client.get(getRequest).actionGet();
    if (getResponse.isSourceEmpty() == false) {
        // extract terms only if the doc source exists
        List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
        terms.addAll(extractedValues);
    }
    return terms;
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) ArrayList(java.util.ArrayList) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 10 with GetRequest

use of org.elasticsearch.action.get.GetRequest in project elasticsearch by elastic.

the class TransportGetTaskAction method getFinishedTaskFromIndex.

/**
     * Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
     * task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
     * coordinating node if the node is no longer part of the cluster.
     */
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE, request.getTaskId().toString());
    get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
    client.get(get, new ActionListener<GetResponse>() {

        @Override
        public void onResponse(GetResponse getResponse) {
            try {
                onGetFinishedTaskFromIndex(getResponse, listener);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception e) {
            if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
                // We haven't yet created the index for the task results so it can't be found.
                listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e, request.getTaskId()));
            } else {
                listener.onFailure(e);
            }
        }
    });
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) GetResponse(org.elasticsearch.action.get.GetResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Aggregations

GetRequest (org.elasticsearch.action.get.GetRequest)17 GetResponse (org.elasticsearch.action.get.GetResponse)12 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)3 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)3 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)3 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)3 List (java.util.List)2 Message (org.apache.camel.Message)2 StringEntity (org.apache.http.entity.StringEntity)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)2 DocWriteResponse (org.elasticsearch.action.DocWriteResponse)2 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)2 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)2 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)2 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)2