Search in sources :

Example 11 with IngestDocument

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

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(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
    processor.execute(ingestDocument);
    Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
    assertThat(convertedValue, equalTo(randomFloat));
}
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 12 with IngestDocument

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

the class ConvertProcessorTests method testConvertStringList.

public void testConvertStringList() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    List<Object> fieldValue = new ArrayList<>();
    List<String> expectedList = new ArrayList<>();
    for (int j = 0; j < numItems; j++) {
        Object randomValue;
        String randomValueString;
        switch(randomIntBetween(0, 2)) {
            case 0:
                float randomFloat = randomFloat();
                randomValue = randomFloat;
                randomValueString = Float.toString(randomFloat);
                break;
            case 1:
                int randomInt = randomInt();
                randomValue = randomInt;
                randomValueString = Integer.toString(randomInt);
                break;
            case 2:
                boolean randomBoolean = randomBoolean();
                randomValue = randomBoolean;
                randomValueString = Boolean.toString(randomBoolean);
                break;
            default:
                throw new UnsupportedOperationException();
        }
        fieldValue.add(randomValue);
        expectedList.add(randomValueString);
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with IngestDocument

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

the class ConvertProcessorTests method testConvertFloatList.

public void testConvertFloatList() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    List<String> fieldValue = new ArrayList<>();
    List<Float> expectedList = new ArrayList<>();
    for (int j = 0; j < numItems; j++) {
        float randomFloat = randomFloat();
        fieldValue.add(Float.toString(randomFloat));
        expectedList.add(randomFloat);
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 14 with IngestDocument

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

the class ConvertProcessorTests method testAutoConvertMatchBoolean.

public void testAutoConvertMatchBoolean() throws Exception {
    boolean randomBoolean = randomBoolean();
    String booleanString = Boolean.toString(randomBoolean);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", booleanString));
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
    processor.execute(ingestDocument);
    Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
    assertThat(convertedValue, 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 15 with IngestDocument

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

the class ConvertProcessorTests method testConvertIntList.

public void testConvertIntList() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    List<String> fieldValue = new ArrayList<>();
    List<Integer> expectedList = new ArrayList<>();
    for (int j = 0; j < numItems; j++) {
        int randomInt = randomInt();
        fieldValue.add(Integer.toString(randomInt));
        expectedList.add(randomInt);
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

IngestDocument (org.elasticsearch.ingest.IngestDocument)170 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)105 Processor (org.elasticsearch.ingest.Processor)97 Matchers.containsString (org.hamcrest.Matchers.containsString)57 HashMap (java.util.HashMap)52 ArrayList (java.util.ArrayList)33 List (java.util.List)27 Map (java.util.Map)22 InputStream (java.io.InputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 IOException (java.io.IOException)6 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)6 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Pipeline (org.elasticsearch.ingest.Pipeline)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4