From 0c88c19c1de8e94dc896d73e9ac05d4e027925eb Mon Sep 17 00:00:00 2001 From: bellengao Date: Thu, 1 Oct 2020 03:06:51 +0800 Subject: [PATCH] Add country_name to the default properties of geoip ingest processor (#62915) --- docs/reference/ingest/processors/geoip.asciidoc | 7 +++++-- .../ingest/geoip/GeoIpProcessor.java | 4 ++-- .../test/ingest_geoip/20_geoip_processor.yml | 15 ++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docs/reference/ingest/processors/geoip.asciidoc b/docs/reference/ingest/processors/geoip.asciidoc index 4ce75e5f2b462..c6ce11c14786b 100644 --- a/docs/reference/ingest/processors/geoip.asciidoc +++ b/docs/reference/ingest/processors/geoip.asciidoc @@ -26,7 +26,7 @@ uncompressed. The `ingest-geoip` config directory is located at `$ES_CONFIG/inge | `field` | yes | - | The field to get the ip address from for the geographical lookup. | `target_field` | no | geoip | The field that will hold the geographical information looked up from the Maxmind database. | `database_file` | no | GeoLite2-City.mmdb | The database filename in the geoip config directory. The ingest-geoip module ships with the GeoLite2-City.mmdb, GeoLite2-Country.mmdb and GeoLite2-ASN.mmdb files. -| `properties` | no | [`continent_name`, `country_iso_code`, `region_iso_code`, `region_name`, `city_name`, `location`] * | Controls what properties are added to the `target_field` based on the geoip lookup. +| `properties` | no | [`continent_name`, `country_iso_code`, `country_name`, `region_iso_code`, `region_name`, `city_name`, `location`] * | Controls what properties are added to the `target_field` based on the geoip lookup. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document | `first_only` | no | `true` | If `true` only first found geoip data will be returned, even if `field` contains array |====== @@ -81,6 +81,7 @@ Which returns: "ip": "8.8.8.8", "geoip": { "continent_name": "North America", + "country_name": "United States", "country_iso_code": "US", "location": { "lat": 37.751, "lon": -97.822 } } @@ -90,7 +91,7 @@ Which returns: // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term":1/"_primary_term" : $body._primary_term/] Here is an example that uses the default country database and adds the -geographical information to the `geo` field based on the `ip` field`. Note that +geographical information to the `geo` field based on the `ip` field. Note that this database is included in the module. So this: [source,console] @@ -130,6 +131,7 @@ returns this: "ip": "8.8.8.8", "geo": { "continent_name": "North America", + "country_name": "United States", "country_iso_code": "US", } } @@ -276,6 +278,7 @@ GET /my_ip_locations/_search "_source" : { "geoip" : { "continent_name" : "North America", + "country_name" : "United States", "country_iso_code" : "US", "location" : { "lon" : -97.822, diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java index 7422eacb84a6b..0c9080f58affc 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java @@ -376,11 +376,11 @@ private Map retrieveAsnGeoData(InetAddress ipAddress) { public static final class Factory implements Processor.Factory { static final Set DEFAULT_CITY_PROPERTIES = Collections.unmodifiableSet(EnumSet.of( - Property.CONTINENT_NAME, Property.COUNTRY_ISO_CODE, Property.REGION_ISO_CODE, + Property.CONTINENT_NAME, Property.COUNTRY_NAME, Property.COUNTRY_ISO_CODE, Property.REGION_ISO_CODE, Property.REGION_NAME, Property.CITY_NAME, Property.LOCATION )); static final Set DEFAULT_COUNTRY_PROPERTIES = Collections.unmodifiableSet(EnumSet.of( - Property.CONTINENT_NAME, Property.COUNTRY_ISO_CODE + Property.CONTINENT_NAME, Property.COUNTRY_NAME, Property.COUNTRY_ISO_CODE )); static final Set DEFAULT_ASN_PROPERTIES = Collections.unmodifiableSet(EnumSet.of( Property.IP, Property.ASN, Property.ORGANIZATION_NAME, Property.NETWORK diff --git a/modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/20_geoip_processor.yml b/modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/20_geoip_processor.yml index 84a942a37cce3..3b5ee3bd55381 100644 --- a/modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/20_geoip_processor.yml +++ b/modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/20_geoip_processor.yml @@ -28,12 +28,13 @@ index: test id: 1 - match: { _source.field1: "128.101.101.101" } - - length: { _source.geoip: 6 } + - length: { _source.geoip: 7 } - match: { _source.geoip.city_name: "Minneapolis" } - match: { _source.geoip.country_iso_code: "US" } - match: { _source.geoip.location.lon: -93.2548 } - match: { _source.geoip.location.lat: 44.9399 } - match: { _source.geoip.region_iso_code: "US-MN" } + - match: { _source.geoip.country_name: "United States" } - match: { _source.geoip.region_name: "Minnesota" } - match: { _source.geoip.continent_name: "North America" } @@ -69,12 +70,13 @@ id: 1 - match: { _source.field1: ["128.101.101.101", "127.0.0.1"] } - length: { _source.geoip: 2 } - - length: { _source.geoip.0: 6 } + - length: { _source.geoip.0: 7 } - match: { _source.geoip.0.city_name: "Minneapolis" } - match: { _source.geoip.0.country_iso_code: "US" } - match: { _source.geoip.0.location.lon: -93.2548 } - match: { _source.geoip.0.location.lat: 44.9399 } - match: { _source.geoip.0.region_iso_code: "US-MN" } + - match: { _source.geoip.0.country_name: "United States" } - match: { _source.geoip.0.region_name: "Minnesota" } - match: { _source.geoip.0.continent_name: "North America" } - match: { _source.geoip.1: null } @@ -109,12 +111,13 @@ index: test id: 1 - match: { _source.field1: ["127.0.0.1", "128.101.101.101", "128.101.101.101"] } - - length: { _source.geoip: 6 } + - length: { _source.geoip: 7 } - match: { _source.geoip.city_name: "Minneapolis" } - match: { _source.geoip.country_iso_code: "US" } - match: { _source.geoip.location.lon: -93.2548 } - match: { _source.geoip.location.lat: 44.9399 } - match: { _source.geoip.region_iso_code: "US-MN" } + - match: { _source.geoip.country_name: "United States" } - match: { _source.geoip.region_name: "Minnesota" } - match: { _source.geoip.continent_name: "North America" } @@ -196,8 +199,9 @@ index: test id: 1 - match: { _source.field1: "128.101.101.101" } - - length: { _source.geoip: 2 } + - length: { _source.geoip: 3 } - match: { _source.geoip.country_iso_code: "US" } + - match: { _source.geoip.country_name: "United States" } - match: { _source.geoip.continent_name: "North America" } --- @@ -259,12 +263,13 @@ index: test id: 2 - match: { _source.field1: "128.101.101.101" } - - length: { _source.geoip: 6 } + - length: { _source.geoip: 7 } - match: { _source.geoip.city_name: "Minneapolis" } - match: { _source.geoip.country_iso_code: "US" } - match: { _source.geoip.location.lon: -93.2548 } - match: { _source.geoip.location.lat: 44.9399 } - match: { _source.geoip.region_iso_code: "US-MN" } + - match: { _source.geoip.country_name: "United States" } - match: { _source.geoip.region_name: "Minnesota" } - match: { _source.geoip.continent_name: "North America" }