2015-08-25 39 views
1

我有一个elasticsearch文档,它有一个geo_points数组。我已经创建的映射:Elasticsearch - MissingMethodException在geo_point阵列上运行distanceInKm

{ 
    "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)values:[28.51818,77.09608]]

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

我在这里做错了什么?

在此先感谢。

回答

2

您的脚本不应该由自己检索第一个地理点,但只需调用distanceInKmlocations场直接,就像这样:

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

引擎盖下的first geo point will be retrieved和距离将是computed on it

+0

感谢您的回答! – R4chi7

+0

以及如何获得从所有指标的距离我的意思不仅是从0,你可以请告诉我,这将是真正对我有帮助? –

+0

请您提出另一个问题,因为您要求提供其他问题。 – Val