use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GrokProcessorTests method testUnmatchedNamesNotIncludedInDocument.
public void testUnmatchedNamesNotIncludedInDocument() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
doc.setFieldValue(fieldName, "3");
Map<String, String> patternBank = new HashMap<>();
patternBank.put("ONETWO", "1|2");
patternBank.put("THREE", "3");
GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), patternBank, Collections.singletonList("%{ONETWO:first}|%{THREE:second}"), fieldName, randomBoolean(), randomBoolean());
processor.execute(doc);
assertFalse(doc.hasField("first"));
assertThat(doc.getFieldValue("second", String.class), equalTo("3"));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GrokProcessorTests method testNotStringField.
public void testNotStringField() {
String fieldName = RandomDocumentPicks.randomFieldName(random());
IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
doc.setFieldValue(fieldName, 1);
GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, false);
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.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GrokProcessorTests method testMissingFieldWithIgnoreMissing.
public void testMissingFieldWithIgnoreMissing() throws Exception {
String fieldName = "foo.bar";
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
GrokProcessor processor = new GrokProcessor(randomAsciiOfLength(10), Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GrokProcessorTests method testMultiplePatternsWithMatchReturn.
public void testMultiplePatternsWithMatchReturn() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
doc.setFieldValue(fieldName, "2");
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, false, false);
processor.execute(doc);
assertThat(doc.hasField("one"), equalTo(false));
assertThat(doc.getFieldValue("two", String.class), equalTo("2"));
assertThat(doc.hasField("three"), equalTo(false));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GsubProcessorTests method testGsubNullValue.
public void testGsubNullValue() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
Processor processor = new GsubProcessor(randomAsciiOfLength(10), "field", Pattern.compile("\\."), "-");
try {
processor.execute(ingestDocument);
fail("processor execution should have failed");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("field [field] is null, cannot match pattern."));
}
}
Aggregations