2016-10-13 6 views
0

にdistanceInKmを使用することに等しくありません。Elasticsearch:_geo_distanceでソートすることによって計算結果はscript_fields Elasticsearch.jsで

elsaticsearchバージョンが2.3.4

コードを使用し、ちょうど一種で_geo_distanceで計算

[ 
    { 
     "_index": "stores_location_v1", 
     "_type": "location_info", 
     "_id": "65", 
     "_score": null, 
     "fields": { 
      "distance": [ 
       632.513773747282 
      ] 
     }, 
     "sort": [ 
      631.9282534390322 
     ] 
    }, 
    { 
     "_index": "stores_location_v1", 
     "_type": "location_info", 
     "_id": "100976", 
     "_score": null, 
     "fields": { 
      "distance": [ 
       772.123560941117 
      ] 
     }, 
     "sort": [ 
      656.1648199724189 
     ] 
    }, 
    { 
     "_index": "stores_location_v1", 
     "_type": "location_info", 
     "_id": "64", 
     "_score": null, 
     "fields": { 
      "distance": [ 
       663.1312353690903 
      ] 
     }, 
     "sort": [ 
      662.5164209175506 
     ] 
    }, 
    { 
     "_index": "stores_location_v1", 
     "_type": "location_info", 
     "_id": "100542", 
     "_score": null, 
     "fields": { 
      "distance": [ 
       695.1804755172814 
      ] 
     }, 
     "sort": [ 
      669.5809632061855 
     ] 
    } 
] 

結果を取得し、この

body: { 
    from: data['offset'] || 0 
    , size: data['limit'] || 20 
    , query: { 
     bool: { 
      must: { 
       range: { 
        state: { 
         gte: 0 
        } 
       } 
      } 
      , filter: { 
       geo_distance_range: { 
        from: data['from'] || '0km' 
        , to: data['to'] || '5km' 
        , location: { 
         lat: data['lat'] 
         , lon: data['lon'] 
        } 
       } 
      } 
     } 
    } 
    , sort: [{ 
     _geo_distance: { 
      location: { 
       lat: data['lat'] 
       , lon: data['lon'] 
      }, order: 'asc' 
      , unit: 'm' 
     } 
    }] 
    , script_fields: { 
     distance: { 
      lang: "groovy", 
      script: "doc['location'].distanceInKm(" + data['lat'] + "," + data['lon'] + ")*1000" 
     } 
    } 
} 

走行のようなものですが計算した結果と等しくありませんscript_fieldsでdistanceInKmメソッドを使用します。

私はこれがある理由を知りたいですか?それから何をすべきか? mベースの計算の代わりに、kmとのためdistanceInKmを交換する方法はあり、その後1000 は、精度の損失の理由のこの部分ですか*?

そしてまた、私はただ一点と他の点との間の距離を計算したい、どのように計算すべきですか?直接使用script_fields`` distanceInKmアプローチですか?

答えて

0

search-request-sort.html#geo-sorting

modules-scripting.html#_document_fields

だけ

distance_type

sort: [{ 
    _geo_distance: { 
     location: { 
      lat: data['lat'] 
      , lon: data['lon'] 
     }, order: 'asc' 
     , unit: 'm' 
     , "distance_type": "arc" 
    } 
}] 
, script_fields: { 
    distance: { 
     lang: "groovy", 
     script: "doc['location'].arcDistance(" + data['lat'] + "," + data['lon'] + ")" 
    } 
} 
ため distance_typearcDistance

同じを使用します

関連する問題