Search in sources :

Example 36 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument 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 37 with IngestDocument

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

the class GrokProcessorTests method testFirstWinNamedCapture.

public void testFirstWinNamedCapture() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    doc.setFieldValue(fieldName, "12");
    Map<String, String> patternBank = new HashMap<>();
    patternBank.put("ONETWO", "1|2");
    GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), patternBank, Collections.singletonList("%{ONETWO:first}%{ONETWO:first}"), fieldName, randomBoolean(), randomBoolean());
    processor.execute(doc);
    assertThat(doc.getFieldValue("first", String.class), equalTo("1"));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 38 with IngestDocument

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

the class GrokProcessorTests method testSetMetadata.

public void testSetMetadata() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    doc.setFieldValue(fieldName, "abc23");
    Map<String, String> patternBank = new HashMap<>();
    patternBank.put("ONE", "1");
    patternBank.put("TWO", "2");
    patternBank.put("THREE", "3");
    GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), patternBank, Arrays.asList("%{ONE:one}", "%{TWO:two}", "%{THREE:three}"), fieldName, true, false);
    processor.execute(doc);
    assertThat(doc.hasField("one"), equalTo(false));
    assertThat(doc.getFieldValue("two", String.class), equalTo("2"));
    assertThat(doc.hasField("three"), equalTo(false));
    assertThat(doc.getFieldValue("_ingest._grok_match_index", String.class), equalTo("1"));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 39 with IngestDocument

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

the class GrokProcessorTests method testCombineSamePatternNameAcrossPatterns.

public void testCombineSamePatternNameAcrossPatterns() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    doc.setFieldValue(fieldName, "1-3");
    Map<String, String> patternBank = new HashMap<>();
    patternBank.put("ONE", "1");
    patternBank.put("TWO", "2");
    patternBank.put("THREE", "3");
    GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), patternBank, Arrays.asList("%{ONE:first}-%{TWO:second}", "%{ONE:first}-%{THREE:second}"), fieldName, randomBoolean(), randomBoolean());
    processor.execute(doc);
    assertThat(doc.getFieldValue("first", String.class), equalTo("1"));
    assertThat(doc.getFieldValue("second", String.class), equalTo("3"));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 40 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument 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

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