ingest-geoip.asciidoc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. [[ingest-geoip]]
  2. === Ingest Geoip Processor Plugin
  3. The GeoIP processor adds information about the geographical location of IP addresses, based on data from the Maxmind databases.
  4. This processor adds this information by default under the `geoip` field. The `geoip` processor can resolve both IPv4 and
  5. IPv6 addresses.
  6. The ingest-geoip plugin ships by default with the GeoLite2 City and GeoLite2 Country geoip2 databases from Maxmind made available
  7. under the CCA-ShareAlike 3.0 license. For more details see, http://dev.maxmind.com/geoip/geoip2/geolite2/
  8. The GeoIP processor can run with other geoip2 databases from Maxmind. The files must be copied into the geoip config directory,
  9. and the `database_file` option should be used to specify the filename of the custom database. Custom database files must be compressed
  10. with gzip. The geoip config directory is located at `$ES_HOME/config/ingest/geoip` and holds the shipped databases too.
  11. [[ingest-geoip-install]]
  12. [float]
  13. ==== Installation
  14. This plugin can be installed using the plugin manager:
  15. [source,sh]
  16. ----------------------------------------------------------------
  17. sudo bin/elasticsearch-plugin install ingest-geoip
  18. ----------------------------------------------------------------
  19. The plugin must be installed on every node in the cluster, and each node must
  20. be restarted after installation.
  21. This plugin can be downloaded for <<plugin-management-custom-url,offline install>> from
  22. {plugin_url}/ingest-geoip/ingest-geoip-{version}.zip.
  23. [[ingest-geoip-remove]]
  24. [float]
  25. ==== Removal
  26. The plugin can be removed with the following command:
  27. [source,sh]
  28. ----------------------------------------------------------------
  29. sudo bin/elasticsearch-plugin remove ingest-geoip
  30. ----------------------------------------------------------------
  31. The node must be stopped before removing the plugin.
  32. [[using-ingest-geoip]]
  33. ==== Using the Geoip Processor in a Pipeline
  34. [[ingest-geoip-options]]
  35. .Geoip options
  36. [options="header"]
  37. |======
  38. | Name | Required | Default | Description
  39. | `field` | yes | - | The field to get the ip address from for the geographical lookup.
  40. | `target_field` | no | geoip | The field that will hold the geographical information looked up from the Maxmind database.
  41. | `database_file` | no | GeoLite2-City.mmdb | The database filename in the geoip config directory. The ingest-geoip plugin ships with the GeoLite2-City.mmdb.gz and GeoLite2-Country.mmdb.gz files.
  42. | `properties` | no | [`continent_name`, `country_iso_code`, `region_name`, `city_name`, `location`] * | Controls what properties are added to the `target_field` based on the geoip lookup.
  43. |======
  44. *Depends on what is available in `database_field`:
  45. * If the GeoLite2 City database is used, then the following fields may be added under the `target_field`: `ip`,
  46. `country_iso_code`, `country_name`, `continent_name`, `region_name`, `city_name`, `timezone`, `latitude`, `longitude`
  47. and `location`. The fields actually added depend on what has been found and which properties were configured in `properties`.
  48. * If the GeoLite2 Country database is used, then the following fields may be added under the `target_field`: `ip`,
  49. `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`.
  50. Here is an example that uses the default city database and adds the geographical information to the `geoip` field based on the `ip` field:
  51. [source,js]
  52. --------------------------------------------------
  53. PUT _ingest/pipeline/geoip
  54. {
  55. "description" : "Add geoip info",
  56. "processors" : [
  57. {
  58. "geoip" : {
  59. "field" : "ip"
  60. }
  61. }
  62. ]
  63. }
  64. PUT my_index/my_type/my_id?pipeline=geoip
  65. {
  66. "ip": "8.8.8.8"
  67. }
  68. GET my_index/my_type/my_id
  69. --------------------------------------------------
  70. // CONSOLE
  71. Which returns:
  72. [source,js]
  73. --------------------------------------------------
  74. {
  75. "found": true,
  76. "_index": "my_index",
  77. "_type": "my_type",
  78. "_id": "my_id",
  79. "_version": 1,
  80. "_source": {
  81. "ip": "8.8.8.8",
  82. "geoip": {
  83. "continent_name": "North America",
  84. "country_iso_code": "US",
  85. "region_name": "California",
  86. "city_name": "Mountain View",
  87. "location": { "lat": 37.386, "lon": -122.0838 }
  88. }
  89. }
  90. }
  91. --------------------------------------------------
  92. // TESTRESPONSE
  93. Here is an example that uses the default country database and adds the
  94. geographical information to the `geo` field based on the `ip` field`. Note that
  95. this database is included in the plugin download. So this:
  96. [source,js]
  97. --------------------------------------------------
  98. PUT _ingest/pipeline/geoip
  99. {
  100. "description" : "Add geoip info",
  101. "processors" : [
  102. {
  103. "geoip" : {
  104. "field" : "ip",
  105. "target_field" : "geo",
  106. "database_file" : "GeoLite2-Country.mmdb.gz"
  107. }
  108. }
  109. ]
  110. }
  111. PUT my_index/my_type/my_id?pipeline=geoip
  112. {
  113. "ip": "8.8.8.8"
  114. }
  115. GET my_index/my_type/my_id
  116. --------------------------------------------------
  117. // CONSOLE
  118. returns this:
  119. [source,js]
  120. --------------------------------------------------
  121. {
  122. "found": true,
  123. "_index": "my_index",
  124. "_type": "my_type",
  125. "_id": "my_id",
  126. "_version": 1,
  127. "_source": {
  128. "ip": "8.8.8.8",
  129. "geo": {
  130. "continent_name": "North America",
  131. "country_iso_code": "US",
  132. }
  133. }
  134. }
  135. --------------------------------------------------
  136. // TESTRESPONSE
  137. Not all IP addresses find geo information from the database, When this
  138. occurs, no `target_field` is inserted into the document.
  139. Here is an example of what documents will be indexed as when information for "93.114.45.13"
  140. cannot be found:
  141. [source,js]
  142. --------------------------------------------------
  143. PUT _ingest/pipeline/geoip
  144. {
  145. "description" : "Add geoip info",
  146. "processors" : [
  147. {
  148. "geoip" : {
  149. "field" : "ip"
  150. }
  151. }
  152. ]
  153. }
  154. PUT my_index/my_type/my_id?pipeline=geoip
  155. {
  156. "ip": "93.114.45.13"
  157. }
  158. GET my_index/my_type/my_id
  159. --------------------------------------------------
  160. // CONSOLE
  161. Which returns:
  162. [source,js]
  163. --------------------------------------------------
  164. {
  165. "found": true,
  166. "_index": "my_index",
  167. "_type": "my_type",
  168. "_id": "my_id",
  169. "_version": 1,
  170. "_source": {
  171. "ip": "93.114.45.13"
  172. }
  173. }
  174. --------------------------------------------------
  175. // TESTRESPONSE