Search in sources :

Example 56 with Processor

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

the class JoinProcessorTests method testJoinStrings.

public void testJoinStrings() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    String separator = randomFrom(SEPARATORS);
    List<String> fieldValue = new ArrayList<>(numItems);
    String expectedResult = "";
    for (int j = 0; j < numItems; j++) {
        String value = randomAsciiOfLengthBetween(1, 10);
        fieldValue.add(value);
        expectedResult += value;
        if (j < numItems - 1) {
            expectedResult += separator;
        }
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new JoinProcessor(randomAsciiOfLength(10), fieldName, separator);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult));
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 57 with Processor

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

the class JoinProcessorTests method testJoinNullValue.

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

Example 58 with Processor

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

the class KeyValueProcessorTests method test.

public void test() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), fieldName, "&", "=", null, "target", false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
    assertThat(ingestDocument.getFieldValue("target.second", List.class), equalTo(Arrays.asList("world", "universe")));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) List(java.util.List)

Example 59 with Processor

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

the class KeyValueProcessorTests method testMissingField.

public void testMissingField() {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), "unknown", "&", "=", null, "target", false);
    IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> processor.execute(ingestDocument));
    assertThat(exception.getMessage(), equalTo("field [unknown] not present as part of path [unknown]"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 60 with Processor

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

the class SetProcessorTests method testSetExistingFields.

public void testSetExistingFields() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument);
    Object fieldValue = RandomDocumentPicks.randomFieldValue(random());
    Processor processor = createSetProcessor(fieldName, fieldValue, true);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.hasField(fieldName), equalTo(true));
    assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(fieldValue));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument)

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