Search in sources :

Example 1 with GetPipelineRequest

use of org.elasticsearch.action.ingest.GetPipelineRequest in project elasticsearch by elastic.

the class RestGetPipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    GetPipelineRequest request = new GetPipelineRequest(Strings.splitStringByCommaToArray(restRequest.param("id")));
    request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
    return channel -> client.admin().cluster().getPipeline(request, new RestStatusToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) GetPipelineRequest(org.elasticsearch.action.ingest.GetPipelineRequest) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) GetPipelineRequest(org.elasticsearch.action.ingest.GetPipelineRequest)

Example 2 with GetPipelineRequest

use of org.elasticsearch.action.ingest.GetPipelineRequest in project elasticsearch by elastic.

the class IngestClientIT method test.

public void test() throws Exception {
    BytesReference source = jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject().bytes();
    PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
    client().admin().cluster().putPipeline(putPipelineRequest).get();
    GetPipelineRequest getPipelineRequest = new GetPipelineRequest("_id");
    GetPipelineResponse getResponse = client().admin().cluster().getPipeline(getPipelineRequest).get();
    assertThat(getResponse.isFound(), is(true));
    assertThat(getResponse.pipelines().size(), equalTo(1));
    assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id"));
    client().prepareIndex("test", "type", "1").setPipeline("_id").setSource("field", "value", "fail", false).get();
    Map<String, Object> doc = client().prepareGet("test", "type", "1").get().getSourceAsMap();
    assertThat(doc.get("field"), equalTo("value"));
    assertThat(doc.get("processed"), equalTo(true));
    client().prepareBulk().add(client().prepareIndex("test", "type", "2").setSource("field", "value2", "fail", false).setPipeline("_id")).get();
    doc = client().prepareGet("test", "type", "2").get().getSourceAsMap();
    assertThat(doc.get("field"), equalTo("value2"));
    assertThat(doc.get("processed"), equalTo(true));
    DeletePipelineRequest deletePipelineRequest = new DeletePipelineRequest("_id");
    WritePipelineResponse response = client().admin().cluster().deletePipeline(deletePipelineRequest).get();
    assertThat(response.isAcknowledged(), is(true));
    getResponse = client().admin().cluster().prepareGetPipeline("_id").get();
    assertThat(getResponse.isFound(), is(false));
    assertThat(getResponse.pipelines().size(), equalTo(0));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) GetPipelineRequest(org.elasticsearch.action.ingest.GetPipelineRequest) WritePipelineResponse(org.elasticsearch.action.ingest.WritePipelineResponse) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest) GetPipelineResponse(org.elasticsearch.action.ingest.GetPipelineResponse)

Aggregations

GetPipelineRequest (org.elasticsearch.action.ingest.GetPipelineRequest)2 IOException (java.io.IOException)1 DeletePipelineRequest (org.elasticsearch.action.ingest.DeletePipelineRequest)1 GetPipelineResponse (org.elasticsearch.action.ingest.GetPipelineResponse)1 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)1 WritePipelineResponse (org.elasticsearch.action.ingest.WritePipelineResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Settings (org.elasticsearch.common.settings.Settings)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 RestStatusToXContentListener (org.elasticsearch.rest.action.RestStatusToXContentListener)1