geoip.asciidoc 9.2 KB

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