【问题标题】:Elasticsearch circle - geo_shape query does not give the result I expectedElasticsearch circle - geo_shape 查询没有给出我预期的结果
【发布时间】:2021-02-25 23:59:17
【问题描述】:

我遇到了圆形 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] 在圆圈内。

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

【问题讨论】:

    标签: elasticsearch kibana


    【解决方案1】:

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

      "coordinates": [
           70.0, 0.0
      ],
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多