ingest-geoip.asciidoc 6.5 KB

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