Search in sources :

Example 61 with IngestDocument

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

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

Example 62 with IngestDocument

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

the class GrokProcessorTests method testNotStringFieldWithIgnoreMissing.

public void testNotStringFieldWithIgnoreMissing() {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    doc.setFieldValue(fieldName, 1);
    GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true, MatcherWatchdog.noop());
    Exception e = expectThrows(Exception.class, () -> processor.execute(doc));
    assertThat(e.getMessage(), equalTo("field [" + fieldName + "] of type [java.lang.Integer] cannot be cast to [java.lang.String]"));
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 63 with IngestDocument

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

the class GrokProcessorTests method testNullField.

public void testNullField() {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    doc.setFieldValue(fieldName, null);
    GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, false, MatcherWatchdog.noop());
    Exception e = expectThrows(Exception.class, () -> processor.execute(doc));
    assertThat(e.getMessage(), equalTo("field [" + fieldName + "] is null, cannot process it."));
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 64 with IngestDocument

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

the class GrokProcessorTests method testMatch.

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

Example 65 with IngestDocument

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

the class GrokProcessorTests method testMissingField.

public void testMissingField() {
    String fieldName = "foo.bar";
    IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, false, MatcherWatchdog.noop());
    Exception e = expectThrows(Exception.class, () -> processor.execute(doc));
    assertThat(e.getMessage(), equalTo("field [foo] not present as part of path [foo.bar]"));
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

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