Search in sources :

Example 66 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

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(randomAlphaOfLength(10), null, patternBank, Arrays.asList("%{ONE:first}-%{TWO:second}", "%{ONE:first}-%{THREE:second}"), fieldName, randomBoolean(), randomBoolean(), MatcherWatchdog.noop());
    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.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 67 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class GrokProcessorTests method testNullFieldWithIgnoreMissing.

public void testNullFieldWithIgnoreMissing() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    originalIngestDocument.setFieldValue(fieldName, null);
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true, MatcherWatchdog.noop());
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 68 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class GrokProcessorTests method testMissingFieldWithIgnoreMissing.

public void testMissingFieldWithIgnoreMissing() throws Exception {
    String fieldName = "foo.bar";
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true, MatcherWatchdog.noop());
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 69 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class JoinProcessorTests method testJoinIntegers.

public void testJoinIntegers() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    String separator = randomFrom(SEPARATORS);
    List<Integer> fieldValue = new ArrayList<>(numItems);
    String expectedResult = "";
    for (int j = 0; j < numItems; j++) {
        int value = randomInt();
        fieldValue.add(value);
        expectedResult += value;
        if (j < numItems - 1) {
            expectedResult += separator;
        }
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, fieldName, separator, fieldName);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult));
}
Also used : Processor(org.opensearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 70 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class JoinProcessorTests method testJoinStrings.

public void testJoinStrings() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    int numItems = randomIntBetween(1, 10);
    String separator = randomFrom(SEPARATORS);
    List<String> fieldValue = new ArrayList<>(numItems);
    String expectedResult = "";
    for (int j = 0; j < numItems; j++) {
        String value = randomAlphaOfLengthBetween(1, 10);
        fieldValue.add(value);
        expectedResult += value;
        if (j < numItems - 1) {
            expectedResult += separator;
        }
    }
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, fieldName, separator, fieldName);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult));
}
Also used : Processor(org.opensearch.ingest.Processor) ArrayList(java.util.ArrayList) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

IngestDocument (org.opensearch.ingest.IngestDocument)252 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)150 Processor (org.opensearch.ingest.Processor)136 Matchers.containsString (org.hamcrest.Matchers.containsString)98 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)51 Map (java.util.Map)37 List (java.util.List)36 GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)19 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)13 TestProcessor (org.opensearch.ingest.TestProcessor)12 SortOrder (org.opensearch.ingest.common.SortProcessor.SortOrder)12 Arrays (java.util.Arrays)11 Collectors (java.util.stream.Collectors)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 LinkedHashMap (java.util.LinkedHashMap)9 RandomDocumentPicks (org.opensearch.ingest.RandomDocumentPicks)9 Name (com.carrotsearch.randomizedtesting.annotations.Name)7 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)7 LinkedList (java.util.LinkedList)7