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"));
}
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]"));
}
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."));
}
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"));
}
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]"));
}
Aggregations