由于公司须要使用一个需求, 经过用户的当前地理位置消息搜索出周边的一些数据, 若是使用php进行大数据计算的话,很是消耗性能,因此采用es
包的使用: php
https://packagist.org/package...html
https://www.cnblogs.com/codeA...git
地理位置的查询:
http://cwiki.apachecn.org/pag...github
查询语法:
https://doc.yonyoucloud.com/d...apache
经纬度查询实例:
https://cloud.tencent.com/inf...json
ES - PHP
https://www.elastic.co/guide/...app
PUT http://localhost:9200/showelasticsearch
PUT http://localhost:9200/show/store/_mappingide
{ "store": { "_all":{ "enabled":false }, "properties": { "id": { "type": "integer" }, "name": { "type": "text", "analyzer": "ik_max_word" }, "type": { "type": "integer" }, "position": { "properties": { "location": { "type": "geo_point" } } } } } }
PUT http://localhost:9200/show/test/2 { "id" : 1, "name" : "建升大厦", "type" : 1, "position":{ "location" : { "lat" : 22.6482057076, "lon" : 114.1250142233 } } } PUT http://localhost:9200/show/test/1 { "id" : 2, "name" : "深圳市第三人民医院", "type" : 1, "position":{ "location" : { "lat" : 22.6352587415, "lon" : 114.1289020619 } } } PUT http://localhost:9200/show/test/3 { "id" : 3, "name" : "深圳百合医院", "type" : 1, "position":{ "location" : { "lat" : 22.6164455768, "lon" : 114.1395956293 } } }
查询全部post
POST http://localhost:9200/show/store/_search
//
{ "query": { "bool": { "must": { "match_all": { } }, "filter": { "geo_distance": { "distance" : "10km", "position.location": { "lat": 22.6497899384, "lon": 114.1258725301 } } } } }, "sort": [ { "_geo_distance": { "position.location": { "lat": 22.6497899384, "lon": 114.1258725301 }, "order": "asc", "unit": "km", "mode": "min" } } ] }
查询+分词
{ "from":3, "size":3, "query": { "bool": { "must": { "match": { "name": "深圳" } }, "filter": { "geo_distance": { "distance" : "100km", "position.location": { "lat": 22.649928, "lon": 114.125646 } } } } }, "sort": [ { "_geo_distance": { "position.location": { "lat": 22.6497899384, "lon": 114.1258725301 }, "order": "asc", "unit": "km", "mode": "min" } } ] }
from: 邓尘锋