Search in sources :

Example 1 with Type

use of org.opensearch.ingest.common.ConvertProcessor.Type in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertNullField.

public void testConvertNullField() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    Type type = randomFrom(Type.values());
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, "field", "field", type, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("Field [field] is null, cannot be converted to type [" + type + "]"));
    }
}
Also used : Type(org.opensearch.ingest.common.ConvertProcessor.Type) Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 2 with Type

use of org.opensearch.ingest.common.ConvertProcessor.Type in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertNonExistingField.

public void testConvertNonExistingField() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Type type = randomFrom(Type.values());
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, type, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("not present as part of path [" + fieldName + "]"));
    }
}
Also used : Type(org.opensearch.ingest.common.ConvertProcessor.Type) Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with Type

use of org.opensearch.ingest.common.ConvertProcessor.Type in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertNullFieldWithIgnoreMissing.

public void testConvertNullFieldWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Type type = randomFrom(Type.values());
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, "field", "field", type, true);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Type(org.opensearch.ingest.common.ConvertProcessor.Type) Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 4 with Type

use of org.opensearch.ingest.common.ConvertProcessor.Type in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertNonExistingFieldWithIgnoreMissing.

public void testConvertNonExistingFieldWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Type type = randomFrom(Type.values());
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, type, true);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Type(org.opensearch.ingest.common.ConvertProcessor.Type) Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

IngestDocument (org.opensearch.ingest.IngestDocument)4 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)4 Processor (org.opensearch.ingest.Processor)4 Type (org.opensearch.ingest.common.ConvertProcessor.Type)4 Matchers.containsString (org.hamcrest.Matchers.containsString)2