如何在查询脚本中创建geo_point对象以计算planeDistance()?

时间:2018-07-02 06:55:56

标签: elasticsearch geolocation elasticsearch-painless

“我的索引”没有geo_point类型字段。而是具有两个双重字段“纬度”和“经度”。

     {
        "_index": "stagingstockv21",
        "_type": "stock",
        "_id": "D1422435",
        "_score": 1,
        "_source": {
          ...
           "lattitude": 68255.9964,
           "longitude": 262151.9964
         }
        ...
     }

有什么方法可以使用脚本来计算距离而不更改当前索引吗?

这是我要修改的查询,考虑到doc['location']是我当前在索引中没有的geo_point:

GET my_locations/_search
{
   "from": 2,
   "size": 3,
   "sort": [
      {
         "_script": {
            "type": "number",
            "script": {
               "lang": "painless",
               "inline": "return doc['location'].planeDistance(params.targetLat, params.targetLong) ;",
               "params": {
                  "targetLat": 19.0678637,
                  "targetLong": 72.9991898
               }
            },
            "order": "asc"
         }
      }
   ]
}

我可以在以下脚本中使用doc['lattitude']doc['longitude']代替doc['location'](geo_point)创建geo_point类型的对象吗?

"inline": "return doc['location'].planeDistance(params.targetLat, params.targetLong) ;"

0 个答案:

没有答案