Search in sources :

Example 71 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class JoinProcessorTests method testJoinNullValue.

public void testJoinNullValue() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, "field", "-", "field");
    try {
        processor.execute(ingestDocument);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("field [field] is null, cannot join."));
    }
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 72 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertInt.

public void testConvertInt() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int randomInt = randomInt();
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomInt);
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, Type.INTEGER, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(randomInt));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 73 with IngestDocument

use of org.opensearch.ingest.IngestDocument 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 74 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testAutoConvertMatchFloat.

public void testAutoConvertMatchFloat() throws Exception {
    float randomFloat = randomFloat();
    String randomString = Float.toString(randomFloat);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomString));
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, "field", "field", Type.AUTO, false);
    processor.execute(ingestDocument);
    Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
    assertThat(convertedValue, equalTo(randomFloat));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 75 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class ConvertProcessorTests method testConvertDoubleError.

public void testConvertDoubleError() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    String value = "string-" + randomAlphaOfLengthBetween(1, 10);
    ingestDocument.setFieldValue(fieldName, value);
    Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, Type.DOUBLE, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("unable to convert [" + value + "] to double"));
    }
}
Also used : 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)252 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)150 Processor (org.opensearch.ingest.Processor)136 Matchers.containsString (org.hamcrest.Matchers.containsString)98 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)51 Map (java.util.Map)37 List (java.util.List)36 GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)19 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)13 TestProcessor (org.opensearch.ingest.TestProcessor)12 SortOrder (org.opensearch.ingest.common.SortProcessor.SortOrder)12 Arrays (java.util.Arrays)11 Collectors (java.util.stream.Collectors)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 LinkedHashMap (java.util.LinkedHashMap)9 RandomDocumentPicks (org.opensearch.ingest.RandomDocumentPicks)9 Name (com.carrotsearch.randomizedtesting.annotations.Name)7 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)7 LinkedList (java.util.LinkedList)7