Search in sources :

Example 21 with IngestDocument

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

the class SplitProcessorTests method testSplitNonExistentWithIgnoreMissing.

public void testSplitNonExistentWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new SplitProcessor(randomAsciiOfLength(10), "field", "\\.", 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 22 with IngestDocument

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

the class SplitProcessorTests method testSplit.

public void testSplit() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "127.0.0.1");
    Processor processor = new SplitProcessor(randomAsciiOfLength(10), fieldName, "\\.", false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(Arrays.asList("127", "0", "0", "1")));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 23 with IngestDocument

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

the class DotExpanderProcessorTests method testEscapeFields_valueField.

public void testEscapeFields_valueField() throws Exception {
    Map<String, Object> source = new HashMap<>();
    source.put("foo.bar", "baz1");
    source.put("foo", "baz2");
    IngestDocument document1 = new IngestDocument(source, Collections.emptyMap());
    Processor processor1 = new DotExpanderProcessor("_tag", null, "foo.bar");
    // foo already exists and if a leaf field and therefor can't be replaced by a map field:
    Exception e = expectThrows(IllegalArgumentException.class, () -> processor1.execute(document1));
    assertThat(e.getMessage(), equalTo("cannot expend [foo.bar], because [foo] is not an object field, but a value field"));
    // so because foo is no branch field but a value field the `foo.bar` field can't be expanded
    // into [foo].[bar], so foo should be renamed first into `[foo].[bar]:
    IngestDocument document = new IngestDocument(source, Collections.emptyMap());
    Processor processor = new RenameProcessor("_tag", "foo", "foo.bar", false);
    processor.execute(document);
    processor = new DotExpanderProcessor("_tag", null, "foo.bar");
    processor.execute(document);
    assertThat(document.getFieldValue("foo", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar.0", String.class), equalTo("baz2"));
    assertThat(document.getFieldValue("foo.bar.1", String.class), equalTo("baz1"));
    source = new HashMap<>();
    source.put("foo.bar", "baz1");
    document = new IngestDocument(source, Collections.emptyMap());
    processor = new DotExpanderProcessor("_tag", null, "foo.bar");
    processor.execute(document);
    assertThat(document.getFieldValue("foo", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", String.class), equalTo("baz1"));
    source = new HashMap<>();
    source.put("foo.bar.baz", "baz1");
    source.put("foo", new HashMap<>(Collections.singletonMap("bar", new HashMap<>())));
    document = new IngestDocument(source, Collections.emptyMap());
    processor = new DotExpanderProcessor("_tag", null, "foo.bar.baz");
    processor.execute(document);
    assertThat(document.getFieldValue("foo", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar.baz", String.class), equalTo("baz1"));
    source = new HashMap<>();
    source.put("foo.bar.baz", "baz1");
    source.put("foo", new HashMap<>(Collections.singletonMap("bar", "baz2")));
    IngestDocument document2 = new IngestDocument(source, Collections.emptyMap());
    Processor processor2 = new DotExpanderProcessor("_tag", null, "foo.bar.baz");
    e = expectThrows(IllegalArgumentException.class, () -> processor2.execute(document2));
    assertThat(e.getMessage(), equalTo("cannot expend [foo.bar.baz], because [foo.bar] is not an object field, but a value field"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) HashMap(java.util.HashMap) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 24 with IngestDocument

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

the class DotExpanderProcessorTests method testEscapeFields.

public void testEscapeFields() throws Exception {
    Map<String, Object> source = new HashMap<>();
    source.put("foo.bar", "baz1");
    IngestDocument document = new IngestDocument(source, Collections.emptyMap());
    DotExpanderProcessor processor = new DotExpanderProcessor("_tag", null, "foo.bar");
    processor.execute(document);
    assertThat(document.getFieldValue("foo", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", String.class), equalTo("baz1"));
    source = new HashMap<>();
    source.put("foo.bar.baz", "value");
    document = new IngestDocument(source, Collections.emptyMap());
    processor = new DotExpanderProcessor("_tag", null, "foo.bar.baz");
    processor.execute(document);
    assertThat(document.getFieldValue("foo", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", Map.class).size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar.baz", String.class), equalTo("value"));
    source = new HashMap<>();
    source.put("foo.bar", "baz1");
    source.put("foo", new HashMap<>(Collections.singletonMap("bar", "baz2")));
    document = new IngestDocument(source, Collections.emptyMap());
    processor = new DotExpanderProcessor("_tag", null, "foo.bar");
    processor.execute(document);
    assertThat(document.getSourceAndMetadata().size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", List.class).size(), equalTo(2));
    assertThat(document.getFieldValue("foo.bar.0", String.class), equalTo("baz2"));
    assertThat(document.getFieldValue("foo.bar.1", String.class), equalTo("baz1"));
    source = new HashMap<>();
    source.put("foo.bar", "2");
    source.put("foo", new HashMap<>(Collections.singletonMap("bar", 1)));
    document = new IngestDocument(source, Collections.emptyMap());
    processor = new DotExpanderProcessor("_tag", null, "foo.bar");
    processor.execute(document);
    assertThat(document.getSourceAndMetadata().size(), equalTo(1));
    assertThat(document.getFieldValue("foo.bar", List.class).size(), equalTo(2));
    assertThat(document.getFieldValue("foo.bar.0", Integer.class), equalTo(1));
    assertThat(document.getFieldValue("foo.bar.1", String.class), equalTo("2"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 25 with IngestDocument

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

the class ForEachProcessorTests method testExecute.

public void testExecute() throws Exception {
    List<String> values = new ArrayList<>();
    values.add("foo");
    values.add("bar");
    values.add("baz");
    IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, Collections.singletonMap("values", values));
    ForEachProcessor processor = new ForEachProcessor("_tag", "values", new UppercaseProcessor("_tag", "_ingest._value", false));
    processor.execute(ingestDocument);
    List result = ingestDocument.getFieldValue("values", List.class);
    assertThat(result.get(0), equalTo("FOO"));
    assertThat(result.get(1), equalTo("BAR"));
    assertThat(result.get(2), equalTo("BAZ"));
}
Also used : ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IngestDocument (org.elasticsearch.ingest.IngestDocument)170 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)105 Processor (org.elasticsearch.ingest.Processor)97 Matchers.containsString (org.hamcrest.Matchers.containsString)57 HashMap (java.util.HashMap)52 ArrayList (java.util.ArrayList)33 List (java.util.List)27 Map (java.util.Map)22 InputStream (java.io.InputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 IOException (java.io.IOException)6 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)6 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Pipeline (org.elasticsearch.ingest.Pipeline)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4