Search in sources :

Example 6 with IngestDocument

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

the class AbstractStringProcessorTestCase method testNullValueWithIgnoreMissing.

public void testNullValueWithIgnoreMissing() throws Exception {
    Processor processor = newProcessor("field", true);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 7 with IngestDocument

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

the class AbstractStringProcessorTestCase method testProcessor.

public void testProcessor() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldValue = RandomDocumentPicks.randomString(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, modifyInput(fieldValue));
    Processor processor = newProcessor(fieldName, randomBoolean());
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult(fieldValue)));
}
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 8 with IngestDocument

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

the class AbstractStringProcessorTestCase method testNullValue.

public void testNullValue() throws Exception {
    Processor processor = newProcessor("field", false);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    Exception e = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
    assertThat(e.getMessage(), equalTo("field [field] is null, cannot process it."));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 9 with IngestDocument

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

the class AppendProcessorTests method testAppendValuesToExistingList.

public void testAppendValuesToExistingList() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    Scalar scalar = randomFrom(Scalar.values());
    List<Object> list = new ArrayList<>();
    int size = randomIntBetween(0, 10);
    for (int i = 0; i < size; i++) {
        list.add(scalar.randomValue());
    }
    List<Object> checkList = new ArrayList<>(list);
    String field = RandomDocumentPicks.addRandomField(random(), ingestDocument, list);
    List<Object> values = new ArrayList<>();
    Processor appendProcessor;
    if (randomBoolean()) {
        Object value = scalar.randomValue();
        values.add(value);
        appendProcessor = createAppendProcessor(field, value);
    } else {
        int valuesSize = randomIntBetween(0, 10);
        for (int i = 0; i < valuesSize; i++) {
            values.add(scalar.randomValue());
        }
        appendProcessor = createAppendProcessor(field, values);
    }
    appendProcessor.execute(ingestDocument);
    Object fieldValue = ingestDocument.getFieldValue(field, Object.class);
    assertThat(fieldValue, sameInstance(list));
    assertThat(list.size(), equalTo(size + values.size()));
    for (int i = 0; i < size; i++) {
        assertThat(list.get(i), equalTo(checkList.get(i)));
    }
    for (int i = size; i < size + values.size(); i++) {
        assertThat(list.get(i), equalTo(values.get(i - size)));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 10 with IngestDocument

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

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