geoip.asciidoc 9.5 KB

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