Search in sources :

Example 1 with PutPipelineRequest

use of org.elasticsearch.action.ingest.PutPipelineRequest 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)

Example 2 with PutPipelineRequest

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

the class IngestClientIT method testBulkWithIngestFailures.

public void testBulkWithIngestFailures() throws Exception {
    createIndex("index");
    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();
    int numRequests = scaledRandomIntBetween(32, 128);
    BulkRequest bulkRequest = new BulkRequest();
    for (int i = 0; i < numRequests; i++) {
        IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i)).setPipeline("_id");
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", i % 2 == 0);
        bulkRequest.add(indexRequest);
    }
    BulkResponse response = client().bulk(bulkRequest).actionGet();
    assertThat(response.getItems().length, equalTo(bulkRequest.requests().size()));
    for (int i = 0; i < bulkRequest.requests().size(); i++) {
        BulkItemResponse itemResponse = response.getItems()[i];
        if (i % 2 == 0) {
            BulkItemResponse.Failure failure = itemResponse.getFailure();
            ElasticsearchException compoundProcessorException = (ElasticsearchException) failure.getCause();
            assertThat(compoundProcessorException.getRootCause().getMessage(), equalTo("test processor failed"));
        } else {
            IndexResponse indexResponse = itemResponse.getResponse();
            assertThat("Expected a successful response but found failure [" + itemResponse.getFailure() + "].", itemResponse.isFailed(), is(false));
            assertThat(indexResponse, notNullValue());
            assertThat(indexResponse.getId(), equalTo(Integer.toString(i)));
            assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
        }
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 3 with PutPipelineRequest

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

the class PipelineStoreTests method testValidateNoIngestInfo.

public void testValidateNoIngestInfo() throws Exception {
    PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
    Exception e = expectThrows(IllegalStateException.class, () -> store.validatePipeline(Collections.emptyMap(), putRequest));
    assertEquals("Ingest info is empty", e.getMessage());
    DiscoveryNode discoveryNode = new DiscoveryNode("_node_id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    IngestInfo ingestInfo = new IngestInfo(Collections.singletonList(new ProcessorInfo("set")));
    store.validatePipeline(Collections.singletonMap(discoveryNode, ingestInfo), putRequest);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 4 with PutPipelineRequest

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

the class IngestClientIT method testPutWithPipelineFactoryError.

public void testPutWithPipelineFactoryError() throws Exception {
    BytesReference source = jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").field("unused", ":sad_face:").endObject().endObject().endArray().endObject().bytes();
    PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
    try {
        client().admin().cluster().putPipeline(putPipelineRequest).get();
    } catch (ExecutionException e) {
        ElasticsearchParseException ex = (ElasticsearchParseException) ExceptionsHelper.unwrap(e, ElasticsearchParseException.class);
        assertNotNull(ex);
        assertThat(ex.getMessage(), equalTo("processor [test] doesn't support one or more provided configuration parameters [unused]"));
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with PutPipelineRequest

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

the class PipelineStoreTests method testCrud.

public void testCrud() throws Exception {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    // Start empty
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
    ClusterState previousClusterState = clusterState;
    clusterState = store.innerPut(putRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    pipeline = store.get(id);
    assertThat(pipeline, notNullValue());
    assertThat(pipeline.getId(), equalTo(id));
    assertThat(pipeline.getDescription(), nullValue());
    assertThat(pipeline.getProcessors().size(), equalTo(1));
    assertThat(pipeline.getProcessors().get(0).getType(), equalTo("set"));
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest(id);
    previousClusterState = clusterState;
    clusterState = store.innerDelete(deleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    pipeline = store.get(id);
    assertThat(pipeline, nullValue());
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ClusterName(org.elasticsearch.cluster.ClusterName) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Aggregations

PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)9 BytesArray (org.elasticsearch.common.bytes.BytesArray)5 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 ClusterName (org.elasticsearch.cluster.ClusterName)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 DeletePipelineRequest (org.elasticsearch.action.ingest.DeletePipelineRequest)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 GetPipelineRequest (org.elasticsearch.action.ingest.GetPipelineRequest)1 GetPipelineResponse (org.elasticsearch.action.ingest.GetPipelineResponse)1