use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class UserAgentProcessorTests method testNonExistentWithoutIgnoreMissing.
public void testNonExistentWithoutIgnoreMissing() throws Exception {
UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), false);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]"));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class UserAgentProcessorTests method testNonExistentWithIgnoreMissing.
public void testNonExistentWithIgnoreMissing() throws Exception {
UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), true);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class UserAgentProcessorTests method testCommonBrowser.
@SuppressWarnings("unchecked")
public void testCommonBrowser() throws Exception {
Map<String, Object> document = new HashMap<>();
document.put("source_field", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
processor.execute(ingestDocument);
Map<String, Object> data = ingestDocument.getSourceAndMetadata();
assertThat(data, hasKey("target_field"));
Map<String, Object> target = (Map<String, Object>) data.get("target_field");
assertThat(target.get("name"), is("Chrome"));
assertThat(target.get("major"), is("33"));
assertThat(target.get("minor"), is("0"));
assertThat(target.get("patch"), is("1750"));
assertNull(target.get("build"));
assertThat(target.get("os"), is("Mac OS X 10.9.2"));
assertThat(target.get("os_name"), is("Mac OS X"));
assertThat(target.get("os_major"), is("10"));
assertThat(target.get("os_minor"), is("9"));
assertThat(target.get("device"), is("Other"));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class UserAgentProcessorTests method testUnknown.
@SuppressWarnings("unchecked")
public void testUnknown() throws Exception {
Map<String, Object> document = new HashMap<>();
document.put("source_field", "Something I made up v42.0.1");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
processor.execute(ingestDocument);
Map<String, Object> data = ingestDocument.getSourceAndMetadata();
assertThat(data, hasKey("target_field"));
Map<String, Object> target = (Map<String, Object>) data.get("target_field");
assertThat(target.get("name"), is("Other"));
assertNull(target.get("major"));
assertNull(target.get("minor"));
assertNull(target.get("patch"));
assertNull(target.get("build"));
assertThat(target.get("os"), is("Other"));
assertThat(target.get("os_name"), is("Other"));
assertNull(target.get("os_major"));
assertNull(target.get("os_minor"));
assertThat(target.get("device"), is("Other"));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class GeoIpProcessorTests method testNonExistentWithIgnoreMissing.
public void testNonExistentWithIgnoreMissing() throws Exception {
InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz");
GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class), true);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
Aggregations