Search in sources :

Example 21 with Processor

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

the class RenameProcessorTests method testRenameAtomicOperationRemoveFails.

public void testRenameAtomicOperationRemoveFails() throws Exception {
    Map<String, Object> source = new HashMap<String, Object>() {

        @Override
        public Object remove(Object key) {
            if (key.equals("list")) {
                throw new UnsupportedOperationException();
            }
            return super.remove(key);
        }
    };
    source.put("list", Collections.singletonList("item"));
    IngestDocument ingestDocument = new IngestDocument(source, Collections.emptyMap());
    Processor processor = new RenameProcessor(randomAsciiOfLength(10), "list", "new_field", false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (UnsupportedOperationException e) {
        //the set failed, the old field has not been removed
        assertThat(ingestDocument.getSourceAndMetadata().containsKey("list"), equalTo(true));
        assertThat(ingestDocument.getSourceAndMetadata().containsKey("new_field"), equalTo(false));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 22 with Processor

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

the class JoinProcessorTests method testJoinNonExistingField.

public void testJoinNonExistingField() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = new JoinProcessor(randomAsciiOfLength(10), fieldName, "-");
    try {
        processor.execute(ingestDocument);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("not present as part of path [" + fieldName + "]"));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 23 with Processor

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

the class KeyValueProcessorTests method testFailFieldSplitMatch.

public void testFailFieldSplitMatch() 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|second=world|second=universe"));
    assertFalse(ingestDocument.hasField("target.second"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 24 with Processor

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

the class ForEachProcessorTests method testRandom.

public void testRandom() throws Exception {
    Processor innerProcessor = new Processor() {

        @Override
        public void execute(IngestDocument ingestDocument) throws Exception {
            String existingValue = ingestDocument.getFieldValue("_ingest._value", String.class);
            ingestDocument.setFieldValue("_ingest._value", existingValue + ".");
        }

        @Override
        public String getType() {
            return null;
        }

        @Override
        public String getTag() {
            return null;
        }
    };
    int numValues = randomIntBetween(1, 32);
    List<String> values = new ArrayList<>(numValues);
    for (int i = 0; i < numValues; i++) {
        values.add("");
    }
    IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, Collections.singletonMap("values", values));
    ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor);
    processor.execute(ingestDocument);
    @SuppressWarnings("unchecked") List<String> result = ingestDocument.getFieldValue("values", List.class);
    assertThat(result.size(), equalTo(numValues));
    for (String r : result) {
        assertThat(r, equalTo("."));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) TestProcessor(org.elasticsearch.ingest.TestProcessor) CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 25 with Processor

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

the class SortProcessorTests method testSortIntegers.

public void testSortIntegers() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    List<Integer> fieldValue = new ArrayList<>(numItems);
    List<Integer> expectedResult = new ArrayList<>(numItems);
    for (int j = 0; j < numItems; j++) {
        Integer value = randomIntBetween(1, 100);
        fieldValue.add(value);
        expectedResult.add(value);
    }
    Collections.sort(expectedResult);
    SortOrder order = randomBoolean() ? SortOrder.ASCENDING : SortOrder.DESCENDING;
    if (order.equals(SortOrder.DESCENDING)) {
        Collections.reverse(expectedResult);
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new SortProcessor(randomAsciiOfLength(10), fieldName, order);
    processor.execute(ingestDocument);
    assertEquals(ingestDocument.getFieldValue(fieldName, List.class), expectedResult);
}
Also used : Processor(org.elasticsearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) SortOrder(org.elasticsearch.ingest.common.SortProcessor.SortOrder) List(java.util.List) ArrayList(java.util.ArrayList) 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