geoip.asciidoc 9.4 KB

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