Search in sources :

Example 6 with Processor

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

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

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

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

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

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