geoip.asciidoc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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`, `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`, and `organization_name`. 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_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 module. So this:
  82. [source,console]
  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-000001/_doc/my_id?pipeline=geoip
  98. {
  99. "ip": "8.8.8.8"
  100. }
  101. GET my-index-000001/_doc/my_id
  102. --------------------------------------------------
  103. returns this:
  104. [source,console-result]
  105. --------------------------------------------------
  106. {
  107. "found": true,
  108. "_index": "my-index-000001",
  109. "_id": "my_id",
  110. "_version": 1,
  111. "_seq_no": 65,
  112. "_primary_term": 1,
  113. "_source": {
  114. "ip": "8.8.8.8",
  115. "geo": {
  116. "continent_name": "North America",
  117. "country_iso_code": "US",
  118. }
  119. }
  120. }
  121. --------------------------------------------------
  122. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  123. Not all IP addresses find geo information from the database, When this
  124. occurs, no `target_field` is inserted into the document.
  125. Here is an example of what documents will be indexed as when information for "80.231.5.0"
  126. cannot be found:
  127. [source,console]
  128. --------------------------------------------------
  129. PUT _ingest/pipeline/geoip
  130. {
  131. "description" : "Add geoip info",
  132. "processors" : [
  133. {
  134. "geoip" : {
  135. "field" : "ip"
  136. }
  137. }
  138. ]
  139. }
  140. PUT my-index-000001/_doc/my_id?pipeline=geoip
  141. {
  142. "ip": "80.231.5.0"
  143. }
  144. GET my-index-000001/_doc/my_id
  145. --------------------------------------------------
  146. Which returns:
  147. [source,console-result]
  148. --------------------------------------------------
  149. {
  150. "_index" : "my-index-000001",
  151. "_id" : "my_id",
  152. "_version" : 1,
  153. "_seq_no" : 71,
  154. "_primary_term": 1,
  155. "found" : true,
  156. "_source" : {
  157. "ip" : "80.231.5.0"
  158. }
  159. }
  160. --------------------------------------------------
  161. // TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  162. [[ingest-geoip-mappings-note]]
  163. ===== Recognizing Location as a Geopoint
  164. Although this processor enriches your document with a `location` field containing
  165. the estimated latitude and longitude of the IP address, this field will not be
  166. indexed as a {ref}/geo-point.html[`geo_point`] type in Elasticsearch without explicitly defining it
  167. as such in the mapping.
  168. You can use the following mapping for the example index above:
  169. [source,console]
  170. --------------------------------------------------
  171. PUT my_ip_locations
  172. {
  173. "mappings": {
  174. "properties": {
  175. "geoip": {
  176. "properties": {
  177. "location": { "type": "geo_point" }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. --------------------------------------------------
  184. ////
  185. [source,console]
  186. --------------------------------------------------
  187. PUT _ingest/pipeline/geoip
  188. {
  189. "description" : "Add geoip info",
  190. "processors" : [
  191. {
  192. "geoip" : {
  193. "field" : "ip"
  194. }
  195. }
  196. ]
  197. }
  198. PUT my_ip_locations/_doc/1?refresh=true&pipeline=geoip
  199. {
  200. "ip": "8.8.8.8"
  201. }
  202. GET /my_ip_locations/_search
  203. {
  204. "query": {
  205. "bool": {
  206. "must": {
  207. "match_all": {}
  208. },
  209. "filter": {
  210. "geo_distance": {
  211. "distance": "1m",
  212. "geoip.location": {
  213. "lon": -97.822,
  214. "lat": 37.751
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. --------------------------------------------------
  222. // TEST[continued]
  223. [source,console-result]
  224. --------------------------------------------------
  225. {
  226. "took" : 3,
  227. "timed_out" : false,
  228. "_shards" : {
  229. "total" : 1,
  230. "successful" : 1,
  231. "skipped" : 0,
  232. "failed" : 0
  233. },
  234. "hits" : {
  235. "total" : {
  236. "value": 1,
  237. "relation": "eq"
  238. },
  239. "max_score" : 1.0,
  240. "hits" : [
  241. {
  242. "_index" : "my_ip_locations",
  243. "_id" : "1",
  244. "_score" : 1.0,
  245. "_source" : {
  246. "geoip" : {
  247. "continent_name" : "North America",
  248. "country_iso_code" : "US",
  249. "location" : {
  250. "lon" : -97.822,
  251. "lat" : 37.751
  252. }
  253. },
  254. "ip" : "8.8.8.8"
  255. }
  256. }
  257. ]
  258. }
  259. }
  260. --------------------------------------------------
  261. // TESTRESPONSE[s/"took" : 3/"took" : $body.took/]
  262. ////
  263. [[ingest-geoip-settings]]
  264. ===== Node Settings
  265. The `geoip` processor supports the following setting:
  266. `ingest.geoip.cache_size`::
  267. The maximum number of results that should be cached. Defaults to `1000`.
  268. Note that these settings are node settings and apply to all `geoip` processors, i.e. there is one cache for all defined `geoip` processors.