我有一个类似下面的数据结构。如何为该结构定义地理索引?
{
"currentGeoLocation": {
"latitude": -10,
"longitude": 1
}
}我尝试了这些命令: 1-
db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation[latitude]","currentGeoLocation[longitude]" ] }); 2-
db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation.latitude","currentGeoLocation.longitude" ] }); 但我认为没有一个是正确工作的。因为在我搜索最近的项目之后,我得到了[]。有什么问题吗?
发布于 2016-05-17 17:47:25
您的第二个索引创建是正确的。
人们必须知道,纬度和经度实际上不是千米单位。在a distance calculator中输入[-10, 1] (这也是关于计算细节的一个很好的读物)告诉您它远离[0,0]的1117 km。由于半径的单位在ArangoDB中是m,因此数字变得很大。
在实际的地点搜索肯定会找到你的商品:
db._query('FOR item IN WITHIN(test, -10, 1, 1) RETURN item').toArray()但是,从[0,0]进行搜索需要更大的半径:
db._query('FOR item IN WITHIN(test, 0, 0, 1200000) RETURN item').toArray()
[
{
"_key" : "840",
"_id" : "test/840",
"_rev" : "840",
"currentGeoLocation" : {
"latitude" : -10,
"longitude" : 1
}
}
]发布于 2016-06-15 04:52:55
根据前面的回答,您使用的是arangosh接口还是arangodb js?
我问是因为arangodb js接口不同。在本例中,您将看到类似如下的内容:
db.collection('testnodes').createGeoIndex(['currentGeoLocation.latitude', 'currentGeoLocation.longitude'])此外,arangodb还提供了一些非常有用的地理定位函数(near,to etc),这些函数都有一个辅助函数来自动计算距离。
https://stackoverflow.com/questions/37225637
复制相似问题