Search in sources :

Example 66 with IngestDocument

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]"));
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) IOException(java.io.IOException)

Example 67 with IngestDocument

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);
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 68 with 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"));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 with IngestDocument

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Aggregations

IngestDocument (org.elasticsearch.ingest.IngestDocument)170 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)105 Processor (org.elasticsearch.ingest.Processor)97 Matchers.containsString (org.hamcrest.Matchers.containsString)57 HashMap (java.util.HashMap)52 ArrayList (java.util.ArrayList)33 List (java.util.List)27 Map (java.util.Map)22 InputStream (java.io.InputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 IOException (java.io.IOException)6 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)6 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Pipeline (org.elasticsearch.ingest.Pipeline)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4