Search in sources :

Example 1 with Type

use of org.elasticsearch.ingest.common.ConvertProcessor.Type in project elasticsearch by elastic.

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(randomAsciiOfLength(10), 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.elasticsearch.ingest.common.ConvertProcessor.Type) Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with Type

use of org.elasticsearch.ingest.common.ConvertProcessor.Type in project elasticsearch by elastic.

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(randomAsciiOfLength(10), "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.elasticsearch.ingest.common.ConvertProcessor.Type) Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 3 with Type

use of org.elasticsearch.ingest.common.ConvertProcessor.Type in project elasticsearch by elastic.

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(randomAsciiOfLength(10), fieldName, fieldName, type, true);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Type(org.elasticsearch.ingest.common.ConvertProcessor.Type) Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with Type

use of org.elasticsearch.ingest.common.ConvertProcessor.Type in project elasticsearch by elastic.

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(randomAsciiOfLength(10), "field", "field", type, true);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Type(org.elasticsearch.ingest.common.ConvertProcessor.Type) Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Aggregations

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