Hi i have an nested object
"root" {
....
"userLocations": {
"type" : "nested",
"include_in_parent" : true,
"properties": {
"id": {
"type": "integer"
},
"location": {
"properties": {
"city": {
"type": "string"
},
"zipCode": {
"type": "string"
},
"countryIsoCode": {
"type": "string"
},
"longitude": {
"type": "float"
},
"latitude": {
"type": "float"
},
"geoPoint" : {
"type": "geo_point"
}
}
}
}
}
i have to one root document n userLocations as nested objects.
I can serach with an native script for the closest distance to an point.
But i can not filter the userLocations.id for the closest distance.
Because userLocations.id is sorted by numeric.
Here is my script:
/**
-
Created by rdeter on 18.12.14.
*/
public class NestedLocation extends AbstractLongSearchScript {
double distance = 100000;
double lat;
double lon;
long id;double tmpDistance;
public NestedLocation(@Nullable Map<String,Object> params) {
lat = ((Double)params.get("lat")).doubleValue();
lon = ((Double)params.get("lon")).doubleValue();
}@Override
public long runAsLong() {List<GeoPoint> list = ((ScriptDocValues.GeoPoints) doc().get("userLocations.location.geoPoint")).getValues(); List<Long> userLocationIds = ((ScriptDocValues.Longs) doc().get("userLocations.id")).getValues(); int z = 0; for (GeoPoint geoPoint : list) { tmpDistance = GeoDistance.PLANE.calculate(geoPoint.getLat(), geoPoint.getLon(), lat, lon, DistanceUnit.KILOMETERS); if (tmpDistance < distance ) { distance = tmpDistance; id = userLocationIds.get(z); } z++; } return id;
}
}
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/46a872e7-cb9e-4230-b15f-74b035890a28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.