Sort and Filter by distance


(Manish) #1

I have following restaurants in an index/type

{
"restaurant" : {
"id" : "1",
"name" : "R1",
"places" : [{ "location" : [24.897564,60.22326] },{ "location" :
[24.91984,60.170425] },{ "location" : [24.911654,60.15944] },
{ "location" : [24.91709,60.17587] } ],
"tags" : [ "chinese", "fastfood" ]
}
}

{
"restaurant" : {
"id" : "2",
"name" : "R2",
"places" : [{ "location" : [24.911654,60.15944] },{ "location" :
[24.96398,60.170563] }],
"tags" : [ "chinese", "fastfood", "cheap" ]
}
}

{
"restaurant" : {
"id" : "3",
"name" : "R3",
"places" : [{ "location" : [24.913908,60.167263] },{ "location" :
[24.897907,60.13356] }],
"tags" : [ "bar" ]
}
}

{
"restaurant" : {
"id" : "4",
"name" : "R4",
"places" : [{ "location" : [24.925697,60.162685] }],
"tags" : [ "indian" ]
}
}

{
"restaurant" : {
"id" : "5",
"name" : "R5",
"places" : [{ "location" : [24.939777,60.161095] }],
"tags" : [ "italian" ]
}
}

I need a query to search for nearest two distinct restaurants from my
current location: "lat" : 60.14727, "lon" : 24.89998.
"location" is of type "geo_point"
One restaurant can be at multiple locations (think of Mc D)


(system) #2