GeoIP processor

The geoip processor adds information about the geographical location of IP addresses, based on data from the Maxmind databases. This processor adds this information by default under the geoip field. The geoip processor can resolve both IPv4 and IPv6 addresses.

The ingest-geoip module ships by default with the GeoLite2 City, GeoLite2 Country and GeoLite2 ASN geoip2 databases from Maxmind made available under the CCA-ShareAlike 4.0 license. For more details see, http://dev.maxmind.com/geoip/geoip2/geolite2/

The geoip processor can run with other GeoIP2 databases from Maxmind. The files must be copied into the ingest-geoip config directory, and the database_file option should be used to specify the filename of the custom database. Custom database files must be stored uncompressed. The ingest-geoip config directory is located at $ES_CONFIG/ingest-geoip.

Using the geoip Processor in a Pipeline

Table 18. geoip options

NameRequiredDefaultDescription

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.

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

*Depends on what is available in database_file:

  • If the GeoLite2 City database is used, then the following fields may be added under the target_field: ip, country_iso_code, country_name, continent_name, region_iso_code, region_name, city_name, timezone, latitude, longitude and location. The fields actually added depend on what has been found and which properties were configured in properties.
  • If the GeoLite2 Country database is used, then the following fields may be added under the target_field: ip, country_iso_code, country_name and continent_name. The fields actually added depend on what has been found and which properties were configured in properties.
  • If the GeoLite2 ASN database is used, then the following fields may be added under the target_field: ip, asn, and organization_name. The fields actually added depend on what has been found and which properties were configured in properties.

Here is an example that uses the default city database and adds the geographical information to the geoip field based on the ip field:

  1. PUT _ingest/pipeline/geoip
  2. {
  3. "description" : "Add geoip info",
  4. "processors" : [
  5. {
  6. "geoip" : {
  7. "field" : "ip"
  8. }
  9. }
  10. ]
  11. }
  12. PUT my-index-00001/_doc/my_id?pipeline=geoip
  13. {
  14. "ip": "8.8.8.8"
  15. }
  16. GET my-index-00001/_doc/my_id

Which returns:

  1. {
  2. "found": true,
  3. "_index": "my-index-00001",
  4. "_type": "_doc",
  5. "_id": "my_id",
  6. "_version": 1,
  7. "_seq_no": 55,
  8. "_primary_term": 1,
  9. "_source": {
  10. "ip": "8.8.8.8",
  11. "geoip": {
  12. "continent_name": "North America",
  13. "country_iso_code": "US",
  14. "location": { "lat": 37.751, "lon": -97.822 }
  15. }
  16. }
  17. }

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 this database is included in the module. So this:

  1. PUT _ingest/pipeline/geoip
  2. {
  3. "description" : "Add geoip info",
  4. "processors" : [
  5. {
  6. "geoip" : {
  7. "field" : "ip",
  8. "target_field" : "geo",
  9. "database_file" : "GeoLite2-Country.mmdb"
  10. }
  11. }
  12. ]
  13. }
  14. PUT my-index-00001/_doc/my_id?pipeline=geoip
  15. {
  16. "ip": "8.8.8.8"
  17. }
  18. GET my-index-00001/_doc/my_id

returns this:

  1. {
  2. "found": true,
  3. "_index": "my-index-00001",
  4. "_type": "_doc",
  5. "_id": "my_id",
  6. "_version": 1,
  7. "_seq_no": 65,
  8. "_primary_term": 1,
  9. "_source": {
  10. "ip": "8.8.8.8",
  11. "geo": {
  12. "continent_name": "North America",
  13. "country_iso_code": "US",
  14. }
  15. }
  16. }

Not all IP addresses find geo information from the database, When this occurs, no target_field is inserted into the document.

Here is an example of what documents will be indexed as when information for “80.231.5.0” cannot be found:

  1. PUT _ingest/pipeline/geoip
  2. {
  3. "description" : "Add geoip info",
  4. "processors" : [
  5. {
  6. "geoip" : {
  7. "field" : "ip"
  8. }
  9. }
  10. ]
  11. }
  12. PUT my-index-00001/_doc/my_id?pipeline=geoip
  13. {
  14. "ip": "80.231.5.0"
  15. }
  16. GET my-index-00001/_doc/my_id

Which returns:

  1. {
  2. "_index" : "my-index-00001",
  3. "_type" : "_doc",
  4. "_id" : "my_id",
  5. "_version" : 1,
  6. "_seq_no" : 71,
  7. "_primary_term": 1,
  8. "found" : true,
  9. "_source" : {
  10. "ip" : "80.231.5.0"
  11. }
  12. }

Recognizing Location as a Geopoint

Although this processor enriches your document with a location field containing the estimated latitude and longitude of the IP address, this field will not be indexed as a geo_point type in Elasticsearch without explicitly defining it as such in the mapping.

You can use the following mapping for the example index above:

  1. PUT my_ip_locations
  2. {
  3. "mappings": {
  4. "properties": {
  5. "geoip": {
  6. "properties": {
  7. "location": { "type": "geo_point" }
  8. }
  9. }
  10. }
  11. }
  12. }

Node Settings

The geoip processor supports the following setting:

ingest.geoip.cache_size

The maximum number of results that should be cached. Defaults to 1000.

Note that these settings are node settings and apply to all geoip processors, i.e. there is one cache for all defined geoip processors.