Search in sources :

Example 46 with Processor

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

the class RemoveProcessorTests method testRemoveNonExistingField.

public void testRemoveNonExistingField() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = new RemoveProcessor(randomAsciiOfLength(10), new TestTemplateService.MockTemplate(fieldName));
    try {
        processor.execute(ingestDocument);
        fail("remove field should have failed");
    } 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) TestTemplateService(org.elasticsearch.ingest.TestTemplateService) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 47 with Processor

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

the class RemoveProcessorTests method testRemoveFields.

public void testRemoveFields() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String field = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument);
    Processor processor = new RemoveProcessor(randomAsciiOfLength(10), new TestTemplateService.MockTemplate(field));
    processor.execute(ingestDocument);
    assertThat(ingestDocument.hasField(field), equalTo(false));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument) TestTemplateService(org.elasticsearch.ingest.TestTemplateService) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 48 with Processor

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

the class RenameProcessorTests method testRenameNonExistingFieldWithIgnoreMissing.

public void testRenameNonExistingFieldWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = new RenameProcessor(randomAsciiOfLength(10), fieldName, RandomDocumentPicks.randomFieldName(random()), true);
    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 49 with Processor

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

the class RenameProcessorTests method testRenameExistingFieldNullValue.

public void testRenameExistingFieldNullValue() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    ingestDocument.setFieldValue(fieldName, null);
    String newFieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = new RenameProcessor(randomAsciiOfLength(10), fieldName, newFieldName, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.hasField(fieldName), equalTo(false));
    assertThat(ingestDocument.hasField(newFieldName), equalTo(true));
    assertThat(ingestDocument.getFieldValue(newFieldName, Object.class), nullValue());
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 50 with Processor

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

the class RenameProcessorTests method testRenameLeafIntoBranch.

public void testRenameLeafIntoBranch() throws Exception {
    Map<String, Object> source = new HashMap<>();
    source.put("foo", "bar");
    IngestDocument ingestDocument = new IngestDocument(source, Collections.emptyMap());
    Processor processor1 = new RenameProcessor(randomAsciiOfLength(10), "foo", "foo.bar", false);
    processor1.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("foo", Map.class), equalTo(Collections.singletonMap("bar", "bar")));
    assertThat(ingestDocument.getFieldValue("foo.bar", String.class), equalTo("bar"));
    Processor processor2 = new RenameProcessor(randomAsciiOfLength(10), "foo.bar", "foo.bar.baz", false);
    processor2.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("foo", Map.class), equalTo(Collections.singletonMap("bar", Collections.singletonMap("baz", "bar"))));
    assertThat(ingestDocument.getFieldValue("foo.bar", Map.class), equalTo(Collections.singletonMap("baz", "bar")));
    assertThat(ingestDocument.getFieldValue("foo.bar.baz", String.class), equalTo("bar"));
    // for fun lets try to restore it (which don't allow today)
    Processor processor3 = new RenameProcessor(randomAsciiOfLength(10), "foo.bar.baz", "foo", false);
    Exception e = expectThrows(IllegalArgumentException.class, () -> processor3.execute(ingestDocument));
    assertThat(e.getMessage(), equalTo("field [foo] already exists"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) HashMap(java.util.HashMap) Map(java.util.Map)

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