geoip.asciidoc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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_HOME/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. |======
  24. *Depends on what is available in `database_field`:
  25. * If the GeoLite2 City database is used, then the following fields may be added under the `target_field`: `ip`,
  26. `country_iso_code`, `country_name`, `continent_name`, `region_iso_code`, `region_name`, `city_name`, `timezone`, `latitude`, `longitude`
  27. and `location`. The fields actually added depend on what has been found and which properties were configured in `properties`.
  28. * If the GeoLite2 Country database is used, then the following fields may be added under the `target_field`: `ip`,
  29. `country_iso_code`, `country_name` and `continent_name`. The fields actually added depend on what has been found and which properties
  30. were configured in `properties`.
  31. * If the GeoLite2 ASN database is used, then the following fields may be added under the `target_field`: `ip`,
  32. `asn`, and `organization_name`. The fields actually added depend on what has been found and which properties were configured
  33. in `properties`.
  34. Here is an example that uses the default city database and adds the geographical information to the `geoip` field based on the `ip` field:
  35. [source,js]
  36. --------------------------------------------------
  37. PUT _ingest/pipeline/geoip
  38. {
  39. "description" : "Add geoip info",
  40. "processors" : [
  41. {
  42. "geoip" : {
  43. "field" : "ip"
  44. }
  45. }
  46. ]
  47. }
  48. PUT my_index/_doc/my_id?pipeline=geoip
  49. {
  50. "ip": "8.8.8.8"
  51. }
  52. GET my_index/_doc/my_id
  53. --------------------------------------------------
  54. // CONSOLE
  55. Which returns:
  56. [source,js]
  57. --------------------------------------------------
  58. {
  59. "found": true,
  60. "_index": "my_index",
  61. "_type": "_doc",
  62. "_id": "my_id",
  63. "_version": 1,
  64. "_seq_no": 55,
  65. "_primary_term": 1,
  66. "_source": {
  67. "ip": "8.8.8.8",
  68. "geoip": {
  69. "continent_name": "North America",
  70. "country_iso_code": "US",
  71. "location": { "lat": 37.751, "lon": -97.822 }
  72. }
  73. }
  74. }
  75. --------------------------------------------------
  76. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term":1/"_primary_term" : $body._primary_term/]
  77. Here is an example that uses the default country database and adds the
  78. geographical information to the `geo` field based on the `ip` field`. Note that
  79. this database is included in the module. So this:
  80. [source,js]
  81. --------------------------------------------------
  82. PUT _ingest/pipeline/geoip
  83. {
  84. "description" : "Add geoip info",
  85. "processors" : [
  86. {
  87. "geoip" : {
  88. "field" : "ip",
  89. "target_field" : "geo",
  90. "database_file" : "GeoLite2-Country.mmdb"
  91. }
  92. }
  93. ]
  94. }
  95. PUT my_index/_doc/my_id?pipeline=geoip
  96. {
  97. "ip": "8.8.8.8"
  98. }
  99. GET my_index/_doc/my_id
  100. --------------------------------------------------
  101. // CONSOLE
  102. returns this:
  103. [source,js]
  104. --------------------------------------------------
  105. {
  106. "found": true,
  107. "_index": "my_index",
  108. "_type": "_doc",
  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,js]
  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/_doc/my_id?pipeline=geoip
  141. {
  142. "ip": "80.231.5.0"
  143. }
  144. GET my_index/_doc/my_id
  145. --------------------------------------------------
  146. // CONSOLE
  147. Which returns:
  148. [source,js]
  149. --------------------------------------------------
  150. {
  151. "_index" : "my_index",
  152. "_type" : "_doc",
  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 explicitely defining it
  169. as such in the mapping.
  170. You can use the following mapping for the example index above:
  171. [source,js]
  172. --------------------------------------------------
  173. PUT my_ip_locations
  174. {
  175. "mappings": {
  176. "_doc": {
  177. "properties": {
  178. "geoip": {
  179. "properties": {
  180. "location": { "type": "geo_point" }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187. --------------------------------------------------
  188. // CONSOLE
  189. ////
  190. [source,js]
  191. --------------------------------------------------
  192. PUT _ingest/pipeline/geoip
  193. {
  194. "description" : "Add geoip info",
  195. "processors" : [
  196. {
  197. "geoip" : {
  198. "field" : "ip"
  199. }
  200. }
  201. ]
  202. }
  203. PUT my_ip_locations/_doc/1?refresh=true&pipeline=geoip
  204. {
  205. "ip": "8.8.8.8"
  206. }
  207. GET /my_ip_locations/_search
  208. {
  209. "query": {
  210. "bool" : {
  211. "must" : {
  212. "match_all" : {}
  213. },
  214. "filter" : {
  215. "geo_distance" : {
  216. "distance" : "1m",
  217. "geoip.location" : {
  218. "lon" : -97.822,
  219. "lat" : 37.751
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. --------------------------------------------------
  227. // CONSOLE
  228. // TEST[continued]
  229. [source,js]
  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. "_type" : "_doc",
  250. "_id" : "1",
  251. "_score" : 1.0,
  252. "_source" : {
  253. "geoip" : {
  254. "continent_name" : "North America",
  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.