Amazon web services 使用弹性搜索地理位置功能查找最常见的位置?
我有一个geojson文件,其中包含一个位置列表,每个位置都有一个经度、纬度和时间戳。注:经度和纬度乘以10000000Amazon web services 使用弹性搜索地理位置功能查找最常见的位置?,amazon-web-services,
elasticsearch,geolocation,location,geojson,Amazon Web Services,
elasticsearch,Geolocation,Location,Geojson,我有一个geojson文件,其中包含一个位置列表,每个位置都有一个经度、纬度和时间戳。注:经度和纬度乘以10000000 { "locations" : [ { "timestampMs" : "1461820561530", "latitudeE7" : -378107308, "longitudeE7" : 1449654070, "accuracy" : 35, "junk_i_want_to_save_but_ignore" : [ { ..
{
"locations" : [ {
"timestampMs" : "1461820561530",
"latitudeE7" : -378107308,
"longitudeE7" : 1449654070,
"accuracy" : 35,
"junk_i_want_to_save_but_ignore" : [ { .. } ]
}, {
"timestampMs" : "1461820455813",
"latitudeE7" : -378107279,
"longitudeE7" : 1449673809,
"accuracy" : 33
}, {
"timestampMs" : "1461820281089",
"latitudeE7" : -378105184,
"longitudeE7" : 1449254023,
"accuracy" : 35
}, {
"timestampMs" : "1461820155814",
"latitudeE7" : -378177434,
"longitudeE7" : 1429653949,
"accuracy" : 34
}
..
其中许多位置将是相同的物理位置(例如用户的家),但显然经度和纬度可能不完全相同
我想使用弹性搜索和它的地理功能来生成一个最常见位置的排名列表,如果这些位置彼此之间的距离在(比如)100米以内,那么它们被认为是相同的
对于每个常见的位置,如果可能的话,我还希望列出它们在该位置的所有时间戳
我非常感谢一个示例查询来帮助我开始
非常感谢。为了使其正常工作,您需要如下修改映射:
PUT /locations
{
"mappings": {
"location": {
"properties": {
"location": {
"type": "geo_point"
},
"timestampMs": {
"type": "long"
},
"accuracy": {
"type": "long"
}
}
}
}
}
PUT /locations/location/1
{
"timestampMs": "1461820561530",
"location": {
"lat": -37.8103308,
"lon": 14.4967407
},
"accuracy": 35
}
然后,在为文档编制索引时,需要将纬度和经度除以10000000,并按如下方式编制索引:
PUT /locations
{
"mappings": {
"location": {
"properties": {
"location": {
"type": "geo_point"
},
"timestampMs": {
"type": "long"
},
"accuracy": {
"type": "long"
}
}
}
}
}
PUT /locations/location/1
{
"timestampMs": "1461820561530",
"location": {
"lat": -37.8103308,
"lon": 14.4967407
},
"accuracy": 35
}
最后,您的搜索查询如下
POST /locations/location/_search
{
"aggregations": {
"zoomedInView": {
"filter": {
"geo_bounding_box": {
"location": {
"top_left": "-37, 14",
"bottom_right": "-38, 15"
}
}
},
"aggregations": {
"zoom1": {
"geohash_grid": {
"field": "location",
"precision": 6
},
"aggs": {
"ts": {
"date_histogram": {
"field": "timestampMs",
"interval": "15m",
"format": "DDD yyyy-MM-dd HH:mm"
}
}
}
}
}
}
}
}
…将产生以下结果:
{
"aggregations": {
"zoomedInView": {
"doc_count": 1,
"zoom1": {
"buckets": [
{
"key": "k362cu",
"doc_count": 1,
"ts": {
"buckets": [
{
"key_as_string": "Thu 2016-04-28 05:15",
"key": 1461820500000,
"doc_count": 1
}
]
}
}
]
}
}
}
}
更新
根据我们的讨论,这里有一个适合您的解决方案。使用,您可以调用API并检索大的JSON文档(使用),提取/转换所有位置并将它们放入Elasticsearch(使用),非常容易
下面是如何按照我最初的回答中描述的格式设置每个事件的过程
http\u poller
可以检索JSON位置(请注意,我已将轮询间隔设置为1天,但您可以将其更改为其他值,或者每次要检索位置时只需手动运行Logstash)将位置数组拆分为单个事件
位置.conf
:
input {
http_poller {
urls => {
get_locations => {
method => get
url => "http://your_api.com/locations.json"
headers => {
Accept => "application/json"
}
}
}
request_timeout => 60
interval => 86400000
codec => "json"
}
}
filter {
split {
field => "locations"
}
ruby {
code => "
event['location'] = {
'lat' => event['locations']['latitudeE7'] / 10000000.0,
'lon' => event['locations']['longitudeE7'] / 10000000.0
}
"
}
mutate {
add_field => {
"timestampMs" => "%{[locations][timestampMs]}"
"accuracy" => "%{[locations][accuracy]}"
"junk_i_want_to_save_but_ignore" => "%{[locations][junk_i_want_to_save_but_ignore]}"
}
remove_field => [
"locations", "@timestamp", "@version"
]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "locations"
document_type => "location"
}
}
然后可以使用以下命令运行:
bin/logstash -f locations.conf
运行该功能后,您可以启动搜索查询,您应该会得到您期望的结果。您能显示示例文档和映射吗?让人们更容易引导你的问题,并尝试解决它。嗨,瓦尔。说得好!我已经包含了上面的示例数据。如果这个GeoJSON数据被正确索引,那么您可以使用
geohash_grid
聚合来查看每个位置在二维空间中的分布情况(大约100米的矩形)。您还可以将其与date\u直方图
aggregation结合起来,查看各点在时间上的分布情况。非常好,听起来很完美。我对弹性搜索和地理信息完全不熟悉,所以我会看看是否能提出一个查询,并让您知道它是否有效。首先,确保正确索引您的数据。像这样的东西应该让你开始:{“位置”:{“lat”:40,“lon”:70},“时间戳”:1458432895726,“准确度”:15}
,其中位置
是一个地理点
,时间戳
和准确度
都是长的
,谢谢你,太棒了!获取每个存储桶中所有时间戳的列表是否很重要?您想要每个时间戳还是希望按分钟、小时、天对它们进行分组,并简单地按组获取它们的数量?嗨,瓦尔,分组的好主意。若有可能按一周中的每一天、每小时和每15分钟的间隔对他们进行分组,那个就太棒了!e、 g.Monday 06 15-29:3意味着在6:15am和6:29am之间的任何一个星期一都有3个事件,但我认为这相当困难?也有可能通过脚本接收数据,以将我的E7数字转换为常规的long和lat,因为我无法控制源数据。干杯我已经用一个date\u柱状图
子聚合更新了我的答案,该子聚合完全满足您的需要,即按15分钟的时间段存储所有时间戳