在 ArangoDB 中定义地理索引 [英] define geo index in ArangoDB

查看:21
本文介绍了在 ArangoDB 中定义地理索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的数据结构.如何为该结构定义地理索引?

I have a data structure like below. how can I define a geo index for that structure?

{
  "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" ] }); 

但我认为没有一个可以正常工作.因为在我搜索最近的项目后,我得到了 [].有什么问题吗?

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.

人们必须知道,纬度和经度实际上并不是公里单位.将 [-10, 1] 输入距离计算器(这也是一本关于计算细节的好读物)告诉你它距离 [0,0] 1117 km.由于ArangoDB中半径的单位是m,所以数字变大了.

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]. Since the unit of the radius is m in ArangoDB, the numbers get big.

在实际地点搜索肯定会找到您的项目:

Searching at the actual spot will for sure find your item:

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

但是,从 [0,0] 搜索需要更大的半径:

But, searching from [0,0] requires a bigger radius:

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 
    } 
  } 
]

这篇关于在 ArangoDB 中定义地理索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆