My Geo Distance Query

hello, anyone
i have a geo distance query function, and anyone can tell me how to realize it with elastichsearch.

hope replies. thank you

description:
there are lots of records, one record one line, every record has a field "positions"
the data format of "positions" is an array, the element is also an array, and it has three fields, first field is lat,
the second field is lon, the last field is distance, unit is meter, such as
"postitions" : [[125.3721,52.7839,50],[ 128.3799,52.7639,100]] , or "postitions": []
there is a request param {"lat":xxxxx, "lon":yyyy }, i hope it will calculate
the distance with postitions,
the process is:
1. calculate {"lat":xxxxx, "lon":yyyy } and the first element of postitions [125.3721,52.7839,50] , and the result distance is low to 50 the thrid filed of the first element, it matchs or , it not match
2. calculate {"lat":xxxxx, "lon":yyyy } and the second element of postitions [ 128.3799,52.7639,100] , and the result distance is low to 100 the thrid filed of the first element, it matchs or , it not match
3. element of postitions has only one match {"lat":xxxxx, "lon":yyyy } it will return the reocord
4. if postitions is empty, it will match any {"lat":xxxxx, "lon":yyyy } , and it will return the record

You may define you field positions as type of Geo-point. ES will save the the pair of latitude and longitude in one Geo-point field.
Here is an Example
PUT my_index/_doc/1
{
"location": {
"lat": 41.12,
"lon": -71.34
}
}

And then you can search all the points you saved
within the distance of the pin point using a geo distance query.

thank you Ethan-zhang. it's not my hope. the data format of postitions is fixed, such as "postitions" : [[125.3721,52.7839,50],[ 128.3799,52.7639,100]], i want input [125.3721,52.7839] named p, p need compare every element of postitions. such as
[125.3721,52.7839] compare [125.3721,52.7839,50] calculate the distance name d, d < 50, it match. or not match.
[125.3721,52.7839] compare ,[ 128.3799,52.7639,100] calculate the distance name d, d < 100, it match. or not match.

if one match , it think this record match and return it

and there are 40 million records

In this case, you probably need to calculate the distance by youself. :grin:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.