Elasticsearch - 在geo_point数组上运行distanceInKm时出现MissingMethodException

时间:2015-08-25 20:39:22

标签: groovy elasticsearch elasticsearch-geo-shape

我有一个包含geo_points数组的elasticsearch文档。我已将映射创建为:

{
    "test": {
        "properties": {
            "locations": {
                "type": "geo_point"
            }
        }
    }
}

现在,我正在尝试创建一个查询,我想在geo_points数组上进行一些处理。我创建了这样的查询:

{
    "query": {
        "filtered": {
            "filter": {
                "script": {
                    "script": "sDistance = doc['locations'].values[0].distanceInKm(28.51818,77.096080);"
                }
            }
        }
    }
}

我想计算点(28.51818,77.096080)与位置数组中第一个元素的距离。

它给了我这个错误:

GroovyScriptExecutionException [MissingMethodException [没有方法签名:org.elasticsearch.common.geo.GeoPoint.distanceInKm()适用于参数类型:(java.lang.Double,java.lang.Double)值:[28.51818,77.09608 ]

我尝试使用sDistance = doc['locations'][0].distanceInKm(28.51818,77.096080);,但也导致了相同的错误。

我在这里做错了什么?

提前致谢。

1 个答案:

答案 0 :(得分:2)

您的脚本不应单独检索第一个地理位置,而只需直接在distanceInKm字段上调用locations,如下所示:

{
  "query": {
    "filtered": {
      "filter": {
        "script": {
          "script": "sDistance = doc['locations'].distanceInKm(28.51818,77.096080);"
        }
      }
    }
  }
}

引擎盖下,first geo point will be retrieved和距离为computed on it