Elasticsearch - MissingMethodException在geo_point数组上运行distanceInKm [英] Elasticsearch - MissingMethodException on running distanceInKm on geo_point array

查看:208
本文介绍了Elasticsearch - MissingMethodException在geo_point数组上运行distanceInKm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有geo_points数组的弹性搜索文档。我已经创建了映射:

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

现在,我正在尝试创建一个查询,我想在其中对geo_points数组进行一些处理。我已经创建了我的查询:

  {
查询:{
{
filter:{
script:{
script:sDistance = doc ['locations']。values [0] .distanceInKm(28.51818,77.096080)
}
}
}
}
}

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



它给我这个错误: / p>

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); ,但也导致相同的错误。



我在这里做错什么?
$ b

提前感谢

解决方案

您的脚本本身不应该检索第一个地理位置,但直接在位置字段之间调用 distanceInKm ,如下所示:

  { 
查询:{
过滤:{
过滤器:{
脚本:{
script:sDistance =位置] distanceInKm(28.51818,77.096080);
}
}
}
}
}

在引擎盖下,第一个地理位置将被检索,距离将为计算出来


I have an elasticsearch document which has an array of geo_points. I have created the mapping as:

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

Now, I am trying to create a query in which I want to do some processing on the array of geo_points. I have created my query like this:

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

I want to calculate the distance of the point (28.51818,77.096080) from the first element in the locations array.

It is giving me this error:

GroovyScriptExecutionException[MissingMethodException[No signature of method: org.elasticsearch.common.geo.GeoPoint.distanceInKm() is applicable for argument types: (java.lang.Double, java.lang.Double) values: [28.51818, 77.09608]]

I tried using sDistance = doc['locations'][0].distanceInKm(28.51818,77.096080); but it also resulted in the same error.

What am I doing wrong here?

Thanks in advance.

解决方案

Your script should not retrieve the first geo point by itself, but simply call distanceInKm on the locations field directly, like this:

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

Under the hood, the first geo point will be retrieved and the distance will be computed on it.

这篇关于Elasticsearch - MissingMethodException在geo_point数组上运行distanceInKm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆