2018-12-22 20:31:07 -05:00
[[geoip-processor]]
2020-08-12 11:49:54 -04:00
=== GeoIP processor
++++
<titleabbrev>GeoIP</titleabbrev>
++++
2016-01-25 15:06:39 -05:00
2018-12-22 09:49:56 -05:00
The `geoip` processor adds information about the geographical location of IP addresses, based on data from the Maxmind databases.
2016-09-28 04:03:43 -04:00
This processor adds this information by default under the `geoip` field. The `geoip` processor can resolve both IPv4 and
IPv6 addresses.
2016-01-25 15:06:39 -05:00
2020-10-29 13:27:17 -04:00
The `ingest-geoip` module ships by default with the GeoLite2 City, GeoLite2 Country and GeoLite2 ASN GeoIP2 databases from Maxmind made available
2017-12-19 08:24:30 -05:00
under the CCA-ShareAlike 4.0 license. For more details see, http://dev.maxmind.com/geoip/geoip2/geolite2/
2016-01-25 15:06:39 -05:00
2020-10-29 13:27:17 -04:00
The `geoip` processor can run with other city, country and ASN GeoIP2 databases
from Maxmind. The database files must be copied into the `ingest-geoip` config
directory located at `$ES_CONFIG/ingest-geoip`. Custom database files must be
stored uncompressed and the extension must be `-City.mmdb`, `-Country.mmdb`, or
`-ASN.mmdb` to indicate the type of the database. These database files can not
have the same filename as any of the built-in database names. The
`database_file` processor option is used to specify the filename of the custom
database to use for the processor.
2016-01-25 15:06:39 -05:00
2016-06-08 15:55:59 -04:00
[[using-ingest-geoip]]
2018-12-22 09:49:56 -05:00
==== Using the `geoip` Processor in a Pipeline
2016-06-08 15:55:59 -04:00
[[ingest-geoip-options]]
2018-12-22 09:49:56 -05:00
.`geoip` options
2016-01-25 15:06:39 -05:00
[options="header"]
|======
| Name | Required | Default | Description
2016-04-20 12:00:11 -04:00
| `field` | yes | - | The field to get the ip address from for the geographical lookup.
2016-01-25 15:06:39 -05:00
| `target_field` | no | geoip | The field that will hold the geographical information looked up from the Maxmind database.
2020-10-29 13:27:17 -04:00
| `database_file` | no | GeoLite2-City.mmdb | The database filename referring to a database the module ships with (GeoLite2-City.mmdb, GeoLite2-Country.mmdb, or GeoLite2-ASN.mmdb) or a custom database in the `ingest-geoip` config directory.
2020-10-01 09:47:51 -04:00
| `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.
2016-12-20 13:53:28 -05:00
| `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
2019-12-06 18:19:09 -05:00
| `first_only` | no | `true` | If `true` only first found geoip data will be returned, even if `field` contains array
2016-01-25 15:06:39 -05:00
|======
2019-05-09 02:52:07 -04:00
*Depends on what is available in `database_file`:
2016-02-11 20:40:32 -05:00
2016-03-04 01:49:31 -05:00
* If the GeoLite2 City database is used, then the following fields may be added under the `target_field`: `ip`,
2018-07-20 14:23:29 -04:00
`country_iso_code`, `country_name`, `continent_name`, `region_iso_code`, `region_name`, `city_name`, `timezone`, `latitude`, `longitude`
2016-04-20 12:00:11 -04:00
and `location`. The fields actually added depend on what has been found and which properties were configured in `properties`.
2016-03-04 01:49:31 -05:00
* If the GeoLite2 Country database is used, then the following fields may be added under the `target_field`: `ip`,
2017-12-22 01:51:44 -05:00
`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`,
2020-10-01 12:01:44 -04:00
`asn`, `organization_name` and `network`. The fields actually added depend on what has been found and which properties were configured
2017-12-22 01:51:44 -05:00
in `properties`.
2016-01-25 15:06:39 -05:00
2020-10-01 12:01:44 -04:00
2016-03-04 01:49:31 -05:00
Here is an example that uses the default city database and adds the geographical information to the `geoip` field based on the `ip` field:
2016-01-25 15:06:39 -05:00
2019-09-06 11:31:13 -04:00
[source,console]
2016-01-25 15:06:39 -05:00
--------------------------------------------------
2016-08-10 08:55:42 -04:00
PUT _ingest/pipeline/geoip
2016-01-25 15:06:39 -05:00
{
2016-08-10 08:55:42 -04:00
"description" : "Add geoip info",
2016-01-25 15:06:39 -05:00
"processors" : [
{
"geoip" : {
2016-04-20 12:00:11 -04:00
"field" : "ip"
2016-01-25 15:06:39 -05:00
}
}
]
}
2020-07-27 15:58:26 -04:00
PUT my-index-00001/_doc/my_id?pipeline=geoip
2016-08-10 08:55:42 -04:00
{
"ip": "8.8.8.8"
}
2020-07-27 15:58:26 -04:00
GET my-index-00001/_doc/my_id
2016-08-10 08:55:42 -04:00
--------------------------------------------------
Which returns:
2019-09-06 16:09:09 -04:00
[source,console-result]
2016-08-10 08:55:42 -04:00
--------------------------------------------------
{
"found": true,
2020-07-27 15:58:26 -04:00
"_index": "my-index-00001",
2018-10-22 14:54:04 -04:00
"_type": "_doc",
2016-08-10 08:55:42 -04:00
"_id": "my_id",
"_version": 1,
2018-12-17 09:22:13 -05:00
"_seq_no": 55,
"_primary_term": 1,
2016-08-10 08:55:42 -04:00
"_source": {
"ip": "8.8.8.8",
"geoip": {
"continent_name": "North America",
2020-10-01 09:47:51 -04:00
"country_name": "United States",
2016-08-10 08:55:42 -04:00
"country_iso_code": "US",
2017-12-19 08:24:30 -05:00
"location": { "lat": 37.751, "lon": -97.822 }
2016-08-10 08:55:42 -04:00
}
}
}
2016-01-25 15:06:39 -05:00
--------------------------------------------------
2018-12-17 09:22:13 -05:00
// TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term":1/"_primary_term" : $body._primary_term/]
2016-01-25 15:06:39 -05:00
2016-08-10 08:55:42 -04:00
Here is an example that uses the default country database and adds the
2020-10-01 09:47:51 -04:00
geographical information to the `geo` field based on the `ip` field. Note that
2018-12-22 07:21:49 -05:00
this database is included in the module. So this:
2016-01-25 15:06:39 -05:00
2019-09-06 11:31:13 -04:00
[source,console]
2016-01-25 15:06:39 -05:00
--------------------------------------------------
2016-08-10 08:55:42 -04:00
PUT _ingest/pipeline/geoip
2016-01-25 15:06:39 -05:00
{
2016-08-10 08:55:42 -04:00
"description" : "Add geoip info",
2016-01-25 15:06:39 -05:00
"processors" : [
{
"geoip" : {
2016-04-20 12:00:11 -04:00
"field" : "ip",
2016-01-25 15:06:39 -05:00
"target_field" : "geo",
2018-03-12 03:07:33 -04:00
"database_file" : "GeoLite2-Country.mmdb"
2016-01-25 15:06:39 -05:00
}
}
]
}
2020-07-27 15:58:26 -04:00
PUT my-index-00001/_doc/my_id?pipeline=geoip
2016-08-10 08:55:42 -04:00
{
"ip": "8.8.8.8"
}
2020-07-27 15:58:26 -04:00
GET my-index-00001/_doc/my_id
2016-08-10 08:55:42 -04:00
--------------------------------------------------
returns this:
2019-09-06 16:09:09 -04:00
[source,console-result]
2016-08-10 08:55:42 -04:00
--------------------------------------------------
{
"found": true,
2020-07-27 15:58:26 -04:00
"_index": "my-index-00001",
2018-10-22 14:54:04 -04:00
"_type": "_doc",
2016-08-10 08:55:42 -04:00
"_id": "my_id",
"_version": 1,
2018-12-17 09:22:13 -05:00
"_seq_no": 65,
"_primary_term": 1,
2016-08-10 08:55:42 -04:00
"_source": {
"ip": "8.8.8.8",
"geo": {
"continent_name": "North America",
2020-10-01 09:47:51 -04:00
"country_name": "United States",
2016-08-10 08:55:42 -04:00
"country_iso_code": "US",
}
}
}
2016-01-25 15:06:39 -05:00
--------------------------------------------------
2018-12-17 09:22:13 -05:00
// TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
2016-09-13 21:12:02 -04:00
Not all IP addresses find geo information from the database, When this
occurs, no `target_field` is inserted into the document.
2017-12-19 08:24:30 -05:00
Here is an example of what documents will be indexed as when information for "80.231.5.0"
2016-09-13 21:12:02 -04:00
cannot be found:
2019-09-06 11:31:13 -04:00
[source,console]
2016-09-13 21:12:02 -04:00
--------------------------------------------------
PUT _ingest/pipeline/geoip
{
"description" : "Add geoip info",
"processors" : [
{
"geoip" : {
"field" : "ip"
}
}
]
}
2018-11-14 23:05:45 -05:00
2020-07-27 15:58:26 -04:00
PUT my-index-00001/_doc/my_id?pipeline=geoip
2016-09-13 21:12:02 -04:00
{
2017-12-19 08:24:30 -05:00
"ip": "80.231.5.0"
2016-09-13 21:12:02 -04:00
}
2018-11-14 23:05:45 -05:00
2020-07-27 15:58:26 -04:00
GET my-index-00001/_doc/my_id
2016-09-13 21:12:02 -04:00
--------------------------------------------------
Which returns:
2019-09-06 16:09:09 -04:00
[source,console-result]
2016-09-13 21:12:02 -04:00
--------------------------------------------------
{
2020-07-27 15:58:26 -04:00
"_index" : "my-index-00001",
2018-11-14 23:05:45 -05:00
"_type" : "_doc",
"_id" : "my_id",
"_version" : 1,
2018-12-17 09:22:13 -05:00
"_seq_no" : 71,
"_primary_term": 1,
2018-11-14 23:05:45 -05:00
"found" : true,
"_source" : {
"ip" : "80.231.5.0"
2016-09-13 21:12:02 -04:00
}
}
--------------------------------------------------
2018-12-17 09:22:13 -05:00
// TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
2016-12-19 04:06:12 -05:00
2018-11-14 23:05:45 -05:00
[[ingest-geoip-mappings-note]]
===== Recognizing Location as a Geopoint
2018-12-22 07:21:49 -05:00
Although this processor enriches your document with a `location` field containing
2018-11-14 23:05:45 -05:00
the estimated latitude and longitude of the IP address, this field will not be
2019-01-07 08:44:12 -05:00
indexed as a {ref}/geo-point.html[`geo_point`] type in Elasticsearch without explicitly defining it
2018-11-14 23:05:45 -05:00
as such in the mapping.
You can use the following mapping for the example index above:
2019-09-06 11:31:13 -04:00
[source,console]
2018-11-14 23:05:45 -05:00
--------------------------------------------------
2019-01-22 09:13:52 -05:00
PUT my_ip_locations
2018-11-14 23:05:45 -05:00
{
"mappings": {
2019-01-22 09:13:52 -05:00
"properties": {
"geoip": {
"properties": {
"location": { "type": "geo_point" }
2018-11-14 23:05:45 -05:00
}
}
}
}
}
--------------------------------------------------
////
2019-09-06 11:31:13 -04:00
[source,console]
2018-11-14 23:05:45 -05:00
--------------------------------------------------
PUT _ingest/pipeline/geoip
{
"description" : "Add geoip info",
"processors" : [
{
"geoip" : {
"field" : "ip"
}
}
]
}
PUT my_ip_locations/_doc/1?refresh=true&pipeline=geoip
{
"ip": "8.8.8.8"
}
GET /my_ip_locations/_search
{
2020-07-21 15:49:58 -04:00
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "1m",
"geoip.location": {
"lon": -97.822,
"lat": 37.751
}
2018-11-14 23:05:45 -05:00
}
2020-07-21 15:49:58 -04:00
}
2018-11-14 23:05:45 -05:00
}
2020-07-21 15:49:58 -04:00
}
2018-11-14 23:05:45 -05:00
}
--------------------------------------------------
// TEST[continued]
2019-09-06 16:09:09 -04:00
[source,console-result]
2018-11-14 23:05:45 -05:00
--------------------------------------------------
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
2018-12-05 13:49:06 -05:00
"total" : {
"value": 1,
"relation": "eq"
},
2018-11-14 23:05:45 -05:00
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_ip_locations",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"geoip" : {
"continent_name" : "North America",
2020-10-01 09:47:51 -04:00
"country_name" : "United States",
2018-11-14 23:05:45 -05:00
"country_iso_code" : "US",
"location" : {
"lon" : -97.822,
"lat" : 37.751
}
},
"ip" : "8.8.8.8"
}
}
]
}
}
--------------------------------------------------
// TESTRESPONSE[s/"took" : 3/"took" : $body.took/]
////
2016-12-19 04:06:12 -05:00
[[ingest-geoip-settings]]
===== Node Settings
2018-12-22 09:49:56 -05:00
The `geoip` processor supports the following setting:
2016-12-19 04:06:12 -05:00
`ingest.geoip.cache_size`::
The maximum number of results that should be cached. Defaults to `1000`.
2018-12-22 09:49:56 -05:00
Note that these settings are node settings and apply to all `geoip` processors, i.e. there is one cache for all defined `geoip` processors.