Search in sources :

Example 86 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class ConvertProcessorTests method testConvertBooleanError.

public void testConvertBooleanError() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    String fieldValue;
    if (randomBoolean()) {
        fieldValue = "string-" + randomAsciiOfLengthBetween(1, 10);
    } else {
        //verify that only proper boolean values are supported and we are strict about it
        fieldValue = randomFrom("on", "off", "yes", "no", "0", "1");
    }
    ingestDocument.setFieldValue(fieldName, fieldValue);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (Exception e) {
        assertThat(e.getMessage(), equalTo("[" + fieldValue + "] is not a boolean value, cannot convert to boolean"));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 87 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class ConvertProcessorTests method testConvertIntError.

public void testConvertIntError() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    String value = "string-" + randomAsciiOfLengthBetween(1, 10);
    ingestDocument.setFieldValue(fieldName, value);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("unable to convert [" + value + "] to integer"));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 88 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class ConvertProcessorTests method testConvertBoolean.

public void testConvertBoolean() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    boolean randomBoolean = randomBoolean();
    String booleanString = Boolean.toString(randomBoolean);
    if (randomBoolean) {
        booleanString = booleanString.toUpperCase(Locale.ROOT);
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, booleanString);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, Boolean.class), equalTo(randomBoolean));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 89 with Processor

use of org.elasticsearch.ingest.Processor 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 90 with Processor

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

Aggregations

Processor (org.elasticsearch.ingest.Processor)101 IngestDocument (org.elasticsearch.ingest.IngestDocument)97 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)57 Matchers.containsString (org.hamcrest.Matchers.containsString)48 ArrayList (java.util.ArrayList)25 List (java.util.List)24 HashMap (java.util.HashMap)13 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)7 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 Map (java.util.Map)5 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)5 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Locale (java.util.Locale)3 TemplateService (org.elasticsearch.ingest.TemplateService)3 ESTestCase (org.elasticsearch.test.ESTestCase)3 Matchers.equalTo (org.hamcrest.Matchers.equalTo)3