Elasticsearch circle - geo_shape 查询没有给出我预期的结果

时间:2021-02-25 14:38:16

标签: elasticsearch kibana

我在圆形 geo_shape 处遇到半径问题。

这里是我的映射;

PUT /circle-example
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape",
        "strategy": "recursive"
      }
    }
  }
}

这里是索引请求示例

POST /circle-example/_doc
{
  "location" : {
    "type" : "circle",
    "coordinates" : [70.0, 1.0],
    "radius" : "25mi"
  }
}

当我计算 [70.0, 0.0] 和 [70.0, 1.0] 之间的距离时,我发现 23,63 英里(小于半径 - 25 英里)。 distance between 2 points

因此;当我使用下面给出的查询进行搜索时,我应该找到文档

GET circle-example/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                  70.0, 0.0
                ],
                "relation": "contains"
              }
            }
          }
        }
      ]
    }
  }
}

但是我没有收到正确的结果。这里截图属于答案; Query Result

这意味着; Elasticsearch 说 [70.0, 0.0] 不在中心为 [70.0, 1.0] 且半径为 25 英里的圆中。 然而;它们之间的距离是 23.63 英里,[70.0, 0.0] 在圆圈中。

你能说说这里有什么问题吗?

1 个答案:

答案 0 :(得分:0)

在您的坐标数组中,第一个组件是经度而不是纬度

  "coordinates": [
       70.0, 0.0
  ],

因此,如果您正确交换距离计算器中的值,您将看到这两点之间的距离实际上是 69 英里,而不是 25 英里。

将文档中的圆半径调整为 69 英里实际上会起作用并返回正确的文档。

enter image description here

相关问题