DocumentDB:ST_DISTANCE 函数不适用于“<”(小于)符号

DocumentDB: ST_DISTANCE function does not work with '<' (smaller than) sign

我有一个完美的查询,如下所示:

SELECT p.id FROM place p WHERE ST_DISTANCE(p.geometry, {'type': 'Point', 'coordinates':[52.0826443333333, 5.11771783333333]} ) > 6000

它 return 是距离地理空间点超过 6000 米的文档的 ID 列表。一切似乎都很好。但是,如果我将“>”(大于)符号转为“<”(小于),它不会给出任何结果。有趣的是,如果我将 WHERE 子句放在 SELECT 语句中,它会执行 return false/true 语句,如下所示:

SELECT ST_DISTANCE(p.geometry, {'type': 'Point', 'coordinates':[52.0826443333333, 5.11771783333333]}) < 6000 AS result FROM place p

它按预期生成真假语句。所以评估似乎有效,但它没有 return 任何输出。目前,我只是使用后者的变通方法,以及 select 计算出的距离。但是现在我必须在其他地方计算一定距离内的点(比如在客户端或存储过程中)。

更新 我使用指定的索引策略 (thanks to this example) 进行了测试:

'indexingPolicy': {'includedPaths': [{'path': '/"geometry"/?', 'indexes': [ {'kind': 'Spatial', 'dataType': 'LineString'}]}, {'path': '/'}]}

这就解决了问题。我仍然认为空间函数在 'greater than' 而不是 'smaller than' 上起作用很奇怪,但我认为它已经解决了。

您应该像这样在该字段上指定 Spatial 索引:

'indexingPolicy': {
    'includedPaths': [
        {
            'path': '/"geometry"/?', 
            'indexes': [ 
               {'kind': 'Spatial', 'dataType': 'LineString'}
            ]
        }, 
        {'path': '/'}
    ]
}