GeoIP解析IP地理位置
Logstash • ziyou 发表了文章 • 0 个评论 • 10469 次浏览 • 2019-12-20 10:09
我们在对IP进行解析的时候使用maxmind提供的提供的GeoLite2,这个是maxmind提供的GeoIP2的免费版本,其准确率稍低于付费版本,可以很好的对IP进行地域解析,可以满足我们的需求。
GeoLite2有提供各种版本的API供开发者使用,我们就主要是用的是java版本的API。具体步骤如下:1、下载maxmind DB数据库
在maxmind官网下载需要的IP解析数据库,里面有两种数据库,一是国家数据库,一是城市数据库,我们使用的基本都是城市数据库,下载选择二进制格式。网页地址:GeoLite2 开源数据库
2、安装软件包,建议使用maven安装此软件包,将以下依赖添加到pom.xml中。
<dependency>
<groupId> com.maxmind.geoip2 </groupId >
<artifactId > geoip2 </artifactId >
<version >2.12.0</version >
</dependency >3、使用// A File object pointing to your GeoIP2 or GeoLite2 database
System.out.println(GeoIP2Test.class.getClassLoader().getResource("GeoLite2-City.mmdb").toString().replaceFirst("/",""));
File database = new File(GeoIP2Test.class.getClassLoader().getResource("GeoLite2-City.mmdb").toString().replaceFirst("file:/",""));
// This creates the DatabaseReader object. To improve performance, reuse
// the object across lookups. The object is thread-safe.
DatabaseReader reader = new DatabaseReader.Builder(database).build();
InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
CityResponse response = reader.city(ipAddress);
Country country = response.getCountry();
System.out.println(country.getIsoCode()); // 'US'
System.out.println(country.getName()); // 'United States'
System.out.println(country.getNames().get("zh-CN")); // '美国'
Subdivision subdivision = response.getMostSpecificSubdivision();
System.out.println(subdivision.getName()); // 'Minnesota'
System.out.println(subdivision.getIsoCode()); // 'MN'
City city = response.getCity();
System.out.println(city.getName()); // 'Minneapolis'
Postal postal = response.getPostal();
System.out.println(postal.getCode()); // '55455'
Location location = response.getLocation();
System.out.println(location.getLatitude()); // 44.9733
System.out.println(location.getLongitude()); // -93.2323 ES5.6.12查询search队列大小是如何突破queue_size的限制的
Elasticsearch • yangjianxuan 回复了问题 • 2 人关注 • 6 个回复 • 4098 次浏览 • 2019-12-20 18:23
kibana安装报错,Lang.String无法转换Lang.Map类型
Kibana • Ombres 回复了问题 • 2 人关注 • 1 个回复 • 4191 次浏览 • 2019-12-20 09:46
错误: [has_parent] no join field has been configured 导致Full GC?
Elasticsearch • 匿名用户 回复了问题 • 2 人关注 • 3 个回复 • 3670 次浏览 • 2019-12-20 08:42
es7.4 使用date search报search_phase_execution_exception
Elasticsearch • istudes 回复了问题 • 2 人关注 • 4 个回复 • 7837 次浏览 • 2019-12-24 16:18
如何对嵌套字段排序,望各位大佬指点一二。
Elasticsearch • 森 回复了问题 • 2 人关注 • 1 个回复 • 1588 次浏览 • 2019-12-20 17:23
es 配置问题。各位大佬帮忙详细解释一番,多谢
Elasticsearch • yu89780012 回复了问题 • 3 人关注 • 4 个回复 • 4329 次浏览 • 2019-12-20 10:14
search after取出全量数据会比scoll更快吗
Elasticsearch • guoyanbiao520 回复了问题 • 7 人关注 • 6 个回复 • 5209 次浏览 • 2021-06-11 18:05
社区日报 第817期 (2019-12-19)
社区日报 • 白衬衣 发表了文章 • 0 个评论 • 1265 次浏览 • 2019-12-19 15:09
http://t.cn/AiDgzlFv
2.Elastic:新手指南
http://t.cn/AiDgzQ4T
3.Elasticsearch冷热分离原理和实践
http://t.cn/AiDgzmPj
编辑:金桥
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
搜索结果未能高亮搜索词 (BM25)
Elasticsearch • dongkaihuahit 回复了问题 • 3 人关注 • 3 个回复 • 1858 次浏览 • 2020-09-24 16:19
大文档对搜索结果影响是什么?看了官方文档有点疑问
回复Elasticsearch • hapjin 发起了问题 • 1 人关注 • 0 个回复 • 1867 次浏览 • 2019-12-19 10:19
什么时候用 track_total_hits =true ,什么时候用count 合适
Elasticsearch • Ombres 回复了问题 • 2 人关注 • 1 个回复 • 6408 次浏览 • 2019-12-19 10:33
咨询下,有没有根据英文词根分词的分词器
Elasticsearch • 匿名用户 回复了问题 • 2 人关注 • 2 个回复 • 2691 次浏览 • 2019-12-19 20:07
es7.3.2 可以查询数据,但是不能修改删除新增数据。也没有报错。不知道什么问题
Elasticsearch • 匿名用户 回复了问题 • 4 人关注 • 5 个回复 • 3406 次浏览 • 2019-12-19 19:36

