use of org.opensearch.action.ingest.PutPipelineRequest in project OpenSearch by opensearch-project.
the class FinalPipelineIT method testFinalPipelineOfOldDestinationIsNotInvoked.
public void testFinalPipelineOfOldDestinationIsNotInvoked() {
Settings settings = Settings.builder().put(IndexSettings.DEFAULT_PIPELINE.getKey(), "default_pipeline").put(IndexSettings.FINAL_PIPELINE.getKey(), "final_pipeline").build();
createIndex("index", settings);
BytesReference defaultPipelineBody = new BytesArray("{\"processors\": [{\"changing_dest\": {}}]}");
client().admin().cluster().putPipeline(new PutPipelineRequest("default_pipeline", defaultPipelineBody, XContentType.JSON)).actionGet();
BytesReference finalPipelineBody = new BytesArray("{\"processors\": [{\"final\": {\"exists\":\"no_such_field\"}}]}");
client().admin().cluster().putPipeline(new PutPipelineRequest("final_pipeline", finalPipelineBody, XContentType.JSON)).actionGet();
IndexResponse indexResponse = client().prepareIndex("index").setId("1").setSource(Collections.singletonMap("field", "value")).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
assertEquals(RestStatus.CREATED, indexResponse.status());
SearchResponse target = client().prepareSearch("target").get();
assertEquals(1, target.getHits().getTotalHits().value);
assertFalse(target.getHits().getAt(0).getSourceAsMap().containsKey("final"));
}
use of org.opensearch.action.ingest.PutPipelineRequest in project OpenSearch by opensearch-project.
the class IngestClientIT method test.
public void test() throws Exception {
BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject());
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").setId("1").setPipeline("_id").setSource("field", "value", "fail", false).get();
Map<String, Object> doc = client().prepareGet("test", "1").get().getSourceAsMap();
assertThat(doc.get("field"), equalTo("value"));
assertThat(doc.get("processed"), equalTo(true));
client().prepareBulk().add(client().prepareIndex("test").setId("2").setSource("field", "value2", "fail", false).setPipeline("_id")).get();
doc = client().prepareGet("test", "2").get().getSourceAsMap();
assertThat(doc.get("field"), equalTo("value2"));
assertThat(doc.get("processed"), equalTo(true));
DeletePipelineRequest deletePipelineRequest = new DeletePipelineRequest("_id");
AcknowledgedResponse 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));
}
use of org.opensearch.action.ingest.PutPipelineRequest in project OpenSearch by opensearch-project.
the class IngestClientIT method testPipelineProcessorOnFailure.
public void testPipelineProcessorOnFailure() throws Exception {
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("pipeline");
source.field("name", "2");
source.endObject();
}
source.endObject();
source.endArray();
}
{
source.startArray("on_failure");
source.startObject();
{
source.startObject("onfailure_processor");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("pipeline");
source.field("name", "3");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("fail");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
client().prepareIndex("test").setId("1").setSource("{}", XContentType.JSON).setPipeline("1").get();
Map<String, Object> inserted = client().prepareGet("test", "1").get().getSourceAsMap();
assertThat(inserted.get("readme"), equalTo("pipeline with id [3] is a bad pipeline"));
}
use of org.opensearch.action.ingest.PutPipelineRequest in project OpenSearch by opensearch-project.
the class IngestClientIT method testBulkWithUpsert.
public void testBulkWithUpsert() throws Exception {
createIndex("index");
BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject());
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest = new IndexRequest("index").id("1").setPipeline("_id");
indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "val1");
bulkRequest.add(indexRequest);
UpdateRequest updateRequest = new UpdateRequest("index", "2");
updateRequest.doc("{}", Requests.INDEX_CONTENT_TYPE);
updateRequest.upsert("{\"field1\":\"upserted_val\"}", XContentType.JSON).upsertRequest().setPipeline("_id");
bulkRequest.add(updateRequest);
BulkResponse response = client().bulk(bulkRequest).actionGet();
assertThat(response.getItems().length, equalTo(bulkRequest.requests().size()));
Map<String, Object> inserted = client().prepareGet("index", "1").get().getSourceAsMap();
assertThat(inserted.get("field1"), equalTo("val1"));
assertThat(inserted.get("processed"), equalTo(true));
Map<String, Object> upserted = client().prepareGet("index", "2").get().getSourceAsMap();
assertThat(upserted.get("field1"), equalTo("upserted_val"));
assertThat(upserted.get("processed"), equalTo(true));
}
use of org.opensearch.action.ingest.PutPipelineRequest in project OpenSearch by opensearch-project.
the class IngestClientIT method testPipelineOriginHeader.
public void testPipelineOriginHeader() throws Exception {
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("pipeline");
source.field("name", "2");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("pipeline");
source.field("name", "3");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
{
XContentBuilder source = jsonBuilder().startObject();
{
source.startArray("processors");
source.startObject();
{
source.startObject("fail");
source.endObject();
}
source.endObject();
source.endArray();
}
source.endObject();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON);
client().admin().cluster().putPipeline(putPipelineRequest).get();
}
Exception e = expectThrows(Exception.class, () -> {
IndexRequest indexRequest = new IndexRequest("test");
indexRequest.source("{}", XContentType.JSON);
indexRequest.setPipeline("1");
client().index(indexRequest).get();
});
IngestProcessorException ingestException = (IngestProcessorException) ExceptionsHelper.unwrap(e, IngestProcessorException.class);
assertThat(ingestException.getHeader("processor_type"), equalTo(Collections.singletonList("fail")));
assertThat(ingestException.getHeader("pipeline_origin"), equalTo(Arrays.asList("3", "2", "1")));
}
Aggregations