简体   繁体   English

在ArangoDB中定义地理索引

[英]define geo index in ArangoDB

I have a data structure like below. 我有一个像下面这样的数据结构。 how can I define a geo index for that structure? 如何为该结构定义地理位置索引?

{
  "currentGeoLocation": {
    "latitude": -10,
    "longitude": 1
  }
}

I tried these command: 1- 我尝试了以下命令:1-

db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation[latitude]","currentGeoLocation[longitude]" ] }); 

2- 2

 db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation.latitude","currentGeoLocation.longitude" ] }); 

but I think none works correctly. 但我认为没有一个能正常工作。 because after I search the nearest items, I got []. 因为在搜索最近的项目后,我得到了[]。 whats the problem? 有什么问题?

Your second index creation is the correct one. 您的第二个索引创建是正确的。

One has to know, that latitude and longtitude aren't actualy km units. 必须知道,纬度和经度实际上并不是千米单位。 Entering [-10, 1] into a distance calculator (which also is a good read about the calculation details) tells you its 1117 km away from [0,0] . 在距离计算器中输入[-10, 1] (这也是有关计算详细信息的好书),它告诉您距离[0,0] 1117 km Since the unit of the radius is m in ArangoDB, the numbers get big. 由于在ArangoDB中半径的单位为m ,因此数字变大。

Searching at the actual spot will for sure find your item: 在实际地点搜索肯定会找到您的物品:

db._query('FOR item IN WITHIN(test, -10, 1, 1) RETURN item').toArray()

But, searching from [0,0] requires a bigger radius: 但是,从[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 
    } 
  } 
]

Following on from the previous answer, are you using the arangosh interface or arangodb js? 在上一个答案之后,您使用的是arangosh接口还是arangodb js?

I ask as the arangodb js interface is different. 我问,因为arangodb js接口是不同的。 In this case you would look at something like: 在这种情况下,您将看到以下内容:

db.collection('testnodes').createGeoIndex(['currentGeoLocation.latitude', 'currentGeoLocation.longitude'])

Also, arangodb does then come with a number of really quite useful Geolocation functions (near, within etc) which have a helper function to automatically calculate the distance. 另外,arangodb确实提供了许多非常有用的地理定位功能(在附近,内部等),这些功能具有自动计算距离的辅助功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM