diff --git a/docs/reference/ingest/processors/user-agent.asciidoc b/docs/reference/ingest/processors/user-agent.asciidoc index f6b6d46fe7b9d..942ba9f148799 100644 --- a/docs/reference/ingest/processors/user-agent.asciidoc +++ b/docs/reference/ingest/processors/user-agent.asciidoc @@ -67,7 +67,9 @@ Which returns "version": "10.10.5", "full": "Mac OS X 10.10.5" }, - "device": "Other" + "device" : { + "name" : "Other" + }, } } } diff --git a/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java b/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java index 6f2518eede673..d83762a5e47ab 100644 --- a/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java +++ b/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java @@ -134,11 +134,13 @@ public IngestDocument execute(IngestDocument ingestDocument) { } break; case DEVICE: + Map deviceDetails = new HashMap<>(1); if (uaClient.device != null && uaClient.device.name != null) { - uaDetails.put("device", uaClient.device.name); + deviceDetails.put("name", uaClient.device.name); } else { - uaDetails.put("device", "Other"); + deviceDetails.put("name", "Other"); } + uaDetails.put("device", deviceDetails); break; } } diff --git a/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java b/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java index 3938fccd832a3..f043cc5369a26 100644 --- a/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java +++ b/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java @@ -110,7 +110,9 @@ public void testCommonBrowser() throws Exception { os.put("version", "10.9.2"); os.put("full", "Mac OS X 10.9.2"); assertThat(target.get("os"), is(os)); - assertThat(target.get("device"), is("Other")); + Map device = new HashMap<>(); + device.put("name", "Other"); + assertThat(target.get("device"), is(device)); } @SuppressWarnings("unchecked") @@ -136,7 +138,9 @@ public void testUncommonDevice() throws Exception { os.put("full", "Android 3.0"); assertThat(target.get("os"), is(os)); - assertThat(target.get("device"), is("Motorola Xoom")); + Map device = new HashMap<>(); + device.put("name", "Motorola Xoom"); + assertThat(target.get("device"), is(device)); } @SuppressWarnings("unchecked") @@ -157,7 +161,9 @@ public void testSpider() throws Exception { assertNull(target.get("version")); assertNull(target.get("os")); - assertThat(target.get("device"), is("Spider")); + Map device = new HashMap<>(); + device.put("name", "Spider"); + assertThat(target.get("device"), is(device)); } @SuppressWarnings("unchecked") @@ -180,7 +186,8 @@ public void testUnknown() throws Exception { assertNull(target.get("build")); assertNull(target.get("os")); - - assertThat(target.get("device"), is("Other")); + Map device = new HashMap<>(); + device.put("name", "Other"); + assertThat(target.get("device"), is(device)); } } diff --git a/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/20_useragent_processor.yml b/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/20_useragent_processor.yml index fc44d7261e80f..a7fe57c557008 100644 --- a/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/20_useragent_processor.yml +++ b/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/20_useragent_processor.yml @@ -32,7 +32,7 @@ - match: { _source.user_agent.original: "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" } - match: { _source.user_agent.os: {"name":"Mac OS X", "version":"10.9.2", "full":"Mac OS X 10.9.2"} } - match: { _source.user_agent.version: "33.0.1750" } - - match: { _source.user_agent.device: "Other" } + - match: { _source.user_agent.device: {"name": "Other" }} --- "Test user agent processor with parameters": diff --git a/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/30_custom_regex.yml b/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/30_custom_regex.yml index ac90a3457fa65..763bea0ee4da0 100644 --- a/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/30_custom_regex.yml +++ b/modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/30_custom_regex.yml @@ -30,6 +30,6 @@ id: 1 - match: { _source.field1: "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" } - match: { _source.user_agent.name: "Test" } - - match: { _source.user_agent.device: "Other" } + - match: { _source.user_agent.device: {"name": "Other" }} - is_false: _source.user_agent.os - is_false: _source.user_agent.version