geoip.asciidoc 9.6 KB

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