Search in sources :

Example 1 with SimulatePipelineRequest

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

the class IngestClientIT method testSimulate.

public void testSimulate() throws Exception {
    BytesReference pipelineSource = jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject().bytes();
    client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON).get();
    GetPipelineResponse getResponse = client().admin().cluster().prepareGetPipeline("_id").get();
    assertThat(getResponse.isFound(), is(true));
    assertThat(getResponse.pipelines().size(), equalTo(1));
    assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id"));
    BytesReference bytes = jsonBuilder().startObject().startArray("docs").startObject().field("_index", "index").field("_type", "type").field("_id", "id").startObject("_source").field("foo", "bar").field("fail", false).endObject().endObject().endArray().endObject().bytes();
    SimulatePipelineResponse response;
    if (randomBoolean()) {
        response = client().admin().cluster().prepareSimulatePipeline(bytes, XContentType.JSON).setId("_id").get();
    } else {
        SimulatePipelineRequest request = new SimulatePipelineRequest(bytes, XContentType.JSON);
        request.setId("_id");
        response = client().admin().cluster().simulatePipeline(request).get();
    }
    assertThat(response.isVerbose(), equalTo(false));
    assertThat(response.getPipelineId(), equalTo("_id"));
    assertThat(response.getResults().size(), equalTo(1));
    assertThat(response.getResults().get(0), instanceOf(SimulateDocumentBaseResult.class));
    SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) response.getResults().get(0);
    Map<String, Object> source = new HashMap<>();
    source.put("foo", "bar");
    source.put("fail", false);
    source.put("processed", true);
    IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, source);
    assertThat(simulateDocumentBaseResult.getIngestDocument().getSourceAndMetadata(), equalTo(ingestDocument.getSourceAndMetadata()));
    assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SimulatePipelineResponse(org.elasticsearch.action.ingest.SimulatePipelineResponse) HashMap(java.util.HashMap) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest) GetPipelineResponse(org.elasticsearch.action.ingest.GetPipelineResponse) SimulateDocumentBaseResult(org.elasticsearch.action.ingest.SimulateDocumentBaseResult)

Example 2 with SimulatePipelineRequest

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

the class RestSimulatePipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    SimulatePipelineRequest request = new SimulatePipelineRequest(sourceTuple.v2(), sourceTuple.v1());
    request.setId(restRequest.param("id"));
    request.setVerbose(restRequest.paramAsBoolean("verbose", false));
    return channel -> client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) XContentType(org.elasticsearch.common.xcontent.XContentType) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) Tuple(org.elasticsearch.common.collect.Tuple) XContentType(org.elasticsearch.common.xcontent.XContentType) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest)

Aggregations

SimulatePipelineRequest (org.elasticsearch.action.ingest.SimulatePipelineRequest)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 GetPipelineResponse (org.elasticsearch.action.ingest.GetPipelineResponse)1 SimulateDocumentBaseResult (org.elasticsearch.action.ingest.SimulateDocumentBaseResult)1 SimulatePipelineResponse (org.elasticsearch.action.ingest.SimulatePipelineResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Tuple (org.elasticsearch.common.collect.Tuple)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentType (org.elasticsearch.common.xcontent.XContentType)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 RestToXContentListener (org.elasticsearch.rest.action.RestToXContentListener)1