Search in sources :

Example 71 with Processor

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

the class JoinProcessorTests method testJoinIntegers.

public void testJoinIntegers() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    String separator = randomFrom(SEPARATORS);
    List<Integer> fieldValue = new ArrayList<>(numItems);
    String expectedResult = "";
    for (int j = 0; j < numItems; j++) {
        int value = randomInt();
        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 72 with Processor

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

the class SetProcessorTests method testSetExistingFieldWithOverrideDisabled.

public void testSetExistingFieldWithOverrideDisabled() throws Exception {
    IngestDocument ingestDocument = new IngestDocument(new HashMap<>(), new HashMap<>());
    Object fieldValue = "foo";
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = createSetProcessor(fieldName, "bar", false);
    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)

Example 73 with Processor

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

the class SetProcessorTests method testSetNewFields.

public void testSetNewFields() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    //used to verify that there are no conflicts between subsequent fields going to be added
    IngestDocument testIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    Object fieldValue = RandomDocumentPicks.randomFieldValue(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), testIngestDocument, fieldValue);
    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)

Example 74 with Processor

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

the class SetProcessorTests method testSetNewFieldWithOverrideDisabled.

public void testSetNewFieldWithOverrideDisabled() throws Exception {
    IngestDocument ingestDocument = new IngestDocument(new HashMap<>(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Object fieldValue = RandomDocumentPicks.randomFieldValue(random());
    Processor processor = createSetProcessor(fieldName, fieldValue, false);
    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)

Example 75 with Processor

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

the class SetProcessorTests method testSetFieldsTypeMismatch.

public void testSetFieldsTypeMismatch() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    ingestDocument.setFieldValue("field", "value");
    Processor processor = createSetProcessor("field.inner", "value", true);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("cannot set [inner] with parent object of type [java.lang.String] as " + "part of path [field.inner]"));
    }
}
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