ingest-geoip.asciidoc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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, GeoLite2 Country and GeoLite2 ASN geoip2 databases from Maxmind made available
  7. under the CCA-ShareAlike 4.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 stored
  10. uncompressed. The geoip config directory is located at `$ES_HOME/config/ingest-geoip` and holds the shipped databases too.
  11. :plugin_name: ingest-geoip
  12. include::install_remove.asciidoc[]
  13. [[using-ingest-geoip]]
  14. ==== Using the Geoip Processor in a Pipeline
  15. [[ingest-geoip-options]]
  16. .Geoip options
  17. [options="header"]
  18. |======
  19. | Name | Required | Default | Description
  20. | `field` | yes | - | The field to get the ip address from for the geographical lookup.
  21. | `target_field` | no | geoip | The field that will hold the geographical information looked up from the Maxmind database.
  22. | `database_file` | no | GeoLite2-City.mmdb | The database filename in the geoip config directory. The ingest-geoip plugin ships with the GeoLite2-City.mmdb, GeoLite2-Country.mmdb and GeoLite2-ASN.mmdb files.
  23. | `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.
  24. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  25. |======
  26. *Depends on what is available in `database_field`:
  27. * If the GeoLite2 City database is used, then the following fields may be added under the `target_field`: `ip`,
  28. `country_iso_code`, `country_name`, `continent_name`, `region_iso_code`, `region_name`, `city_name`, `timezone`, `latitude`, `longitude`
  29. and `location`. The fields actually added depend on what has been found and which properties were configured in `properties`.
  30. * If the GeoLite2 Country database is used, then the following fields may be added under the `target_field`: `ip`,
  31. `country_iso_code`, `country_name` and `continent_name`. The fields actually added depend on what has been found and which properties
  32. were configured in `properties`.
  33. * If the GeoLite2 ASN database is used, then the following fields may be added under the `target_field`: `ip`,
  34. `asn`, and `organization_name`. The fields actually added depend on what has been found and which properties were configured
  35. in `properties`.
  36. Here is an example that uses the default city database and adds the geographical information to the `geoip` field based on the `ip` field:
  37. [source,js]
  38. --------------------------------------------------
  39. PUT _ingest/pipeline/geoip
  40. {
  41. "description" : "Add geoip info",
  42. "processors" : [
  43. {
  44. "geoip" : {
  45. "field" : "ip"
  46. }
  47. }
  48. ]
  49. }
  50. PUT my_index/_doc/my_id?pipeline=geoip
  51. {
  52. "ip": "8.8.8.8"
  53. }
  54. GET my_index/_doc/my_id
  55. --------------------------------------------------
  56. // CONSOLE
  57. Which returns:
  58. [source,js]
  59. --------------------------------------------------
  60. {
  61. "found": true,
  62. "_index": "my_index",
  63. "_type": "_doc",
  64. "_id": "my_id",
  65. "_version": 1,
  66. "_seq_no": 55,
  67. "_primary_term": 1,
  68. "_source": {
  69. "ip": "8.8.8.8",
  70. "geoip": {
  71. "continent_name": "North America",
  72. "country_iso_code": "US",
  73. "location": { "lat": 37.751, "lon": -97.822 }
  74. }
  75. }
  76. }
  77. --------------------------------------------------
  78. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term":1/"_primary_term" : $body._primary_term/]
  79. Here is an example that uses the default country database and adds the
  80. geographical information to the `geo` field based on the `ip` field`. Note that
  81. this database is included in the plugin download. So this:
  82. [source,js]
  83. --------------------------------------------------
  84. PUT _ingest/pipeline/geoip
  85. {
  86. "description" : "Add geoip info",
  87. "processors" : [
  88. {
  89. "geoip" : {
  90. "field" : "ip",
  91. "target_field" : "geo",
  92. "database_file" : "GeoLite2-Country.mmdb"
  93. }
  94. }
  95. ]
  96. }
  97. PUT my_index/_doc/my_id?pipeline=geoip
  98. {
  99. "ip": "8.8.8.8"
  100. }
  101. GET my_index/_doc/my_id
  102. --------------------------------------------------
  103. // CONSOLE
  104. returns this:
  105. [source,js]
  106. --------------------------------------------------
  107. {
  108. "found": true,
  109. "_index": "my_index",
  110. "_type": "_doc",
  111. "_id": "my_id",
  112. "_version": 1,
  113. "_seq_no": 65,
  114. "_primary_term": 1,
  115. "_source": {
  116. "ip": "8.8.8.8",
  117. "geo": {
  118. "continent_name": "North America",
  119. "country_iso_code": "US",
  120. }
  121. }
  122. }
  123. --------------------------------------------------
  124. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  125. Not all IP addresses find geo information from the database, When this
  126. occurs, no `target_field` is inserted into the document.
  127. Here is an example of what documents will be indexed as when information for "80.231.5.0"
  128. cannot be found:
  129. [source,js]
  130. --------------------------------------------------
  131. PUT _ingest/pipeline/geoip
  132. {
  133. "description" : "Add geoip info",
  134. "processors" : [
  135. {
  136. "geoip" : {
  137. "field" : "ip"
  138. }
  139. }
  140. ]
  141. }
  142. PUT my_index/_doc/my_id?pipeline=geoip
  143. {
  144. "ip": "80.231.5.0"
  145. }
  146. GET my_index/_doc/my_id
  147. --------------------------------------------------
  148. // CONSOLE
  149. Which returns:
  150. [source,js]
  151. --------------------------------------------------
  152. {
  153. "_index" : "my_index",
  154. "_type" : "_doc",
  155. "_id" : "my_id",
  156. "_version" : 1,
  157. "_seq_no" : 71,
  158. "_primary_term": 1,
  159. "found" : true,
  160. "_source" : {
  161. "ip" : "80.231.5.0"
  162. }
  163. }
  164. --------------------------------------------------
  165. // TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  166. [[ingest-geoip-mappings-note]]
  167. ===== Recognizing Location as a Geopoint
  168. Although this plugin enriches your document with a `location` field containing
  169. the estimated latitude and longitude of the IP address, this field will not be
  170. indexed as a {ref}/geo-point.html[`geo_point`] type in Elasticsearch without explicitely defining it
  171. as such in the mapping.
  172. You can use the following mapping for the example index above:
  173. [source,js]
  174. --------------------------------------------------
  175. PUT my_ip_locations
  176. {
  177. "mappings": {
  178. "_doc": {
  179. "properties": {
  180. "geoip": {
  181. "properties": {
  182. "location": { "type": "geo_point" }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. --------------------------------------------------
  190. // CONSOLE
  191. ////
  192. [source,js]
  193. --------------------------------------------------
  194. PUT _ingest/pipeline/geoip
  195. {
  196. "description" : "Add geoip info",
  197. "processors" : [
  198. {
  199. "geoip" : {
  200. "field" : "ip"
  201. }
  202. }
  203. ]
  204. }
  205. PUT my_ip_locations/_doc/1?refresh=true&pipeline=geoip
  206. {
  207. "ip": "8.8.8.8"
  208. }
  209. GET /my_ip_locations/_search
  210. {
  211. "query": {
  212. "bool" : {
  213. "must" : {
  214. "match_all" : {}
  215. },
  216. "filter" : {
  217. "geo_distance" : {
  218. "distance" : "1m",
  219. "geoip.location" : {
  220. "lon" : -97.822,
  221. "lat" : 37.751
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. --------------------------------------------------
  229. // CONSOLE
  230. // TEST[continued]
  231. [source,js]
  232. --------------------------------------------------
  233. {
  234. "took" : 3,
  235. "timed_out" : false,
  236. "_shards" : {
  237. "total" : 1,
  238. "successful" : 1,
  239. "skipped" : 0,
  240. "failed" : 0
  241. },
  242. "hits" : {
  243. "total" : {
  244. "value": 1,
  245. "relation": "eq"
  246. },
  247. "max_score" : 1.0,
  248. "hits" : [
  249. {
  250. "_index" : "my_ip_locations",
  251. "_type" : "_doc",
  252. "_id" : "1",
  253. "_score" : 1.0,
  254. "_source" : {
  255. "geoip" : {
  256. "continent_name" : "North America",
  257. "country_iso_code" : "US",
  258. "location" : {
  259. "lon" : -97.822,
  260. "lat" : 37.751
  261. }
  262. },
  263. "ip" : "8.8.8.8"
  264. }
  265. }
  266. ]
  267. }
  268. }
  269. --------------------------------------------------
  270. // TESTRESPONSE[s/"took" : 3/"took" : $body.took/]
  271. ////
  272. [[ingest-geoip-settings]]
  273. ===== Node Settings
  274. The geoip processor supports the following setting:
  275. `ingest.geoip.cache_size`::
  276. The maximum number of results that should be cached. Defaults to `1000`.
  277. Note that these settings are node settings and apply to all geoip processors, i.e. there is one cache for all defined geoip processors.