Search in sources :

Example 76 with Processor

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

the class SetProcessorTests method testSetMetadata.

public void testSetMetadata() throws Exception {
    IngestDocument.MetaData randomMetaData = randomFrom(IngestDocument.MetaData.values());
    Processor processor = createSetProcessor(randomMetaData.getFieldName(), "_value", true);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(randomMetaData.getFieldName(), String.class), Matchers.equalTo("_value"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 77 with Processor

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

the class SetProcessorTests method testSetExistingNullFieldWithOverrideDisabled.

public void testSetExistingNullFieldWithOverrideDisabled() throws Exception {
    IngestDocument ingestDocument = new IngestDocument(new HashMap<>(), new HashMap<>());
    Object fieldValue = null;
    Object newValue = "bar";
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = createSetProcessor(fieldName, newValue, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.hasField(fieldName), equalTo(true));
    assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(newValue));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 78 with Processor

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

the class AttachmentProcessorTests method testNullValueWithIgnoreMissing.

public void testNullValueWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("source_field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new AttachmentProcessor(randomAsciiOfLength(10), "source_field", "randomTarget", null, 10, 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 79 with Processor

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

the class AbstractStringProcessorTestCase method testFieldNotFound.

public void testFieldNotFound() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = newProcessor(fieldName, false);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    Exception e = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
    assertThat(e.getMessage(), containsString("not present as part of path [" + fieldName + "]"));
}
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 80 with Processor

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

the class AbstractStringProcessorTestCase method testFieldNotFoundWithIgnoreMissing.

public void testFieldNotFoundWithIgnoreMissing() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    Processor processor = newProcessor(fieldName, true);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    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) 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