Computing the nearest distance from an array of properties containing a geo_point

Hello,

I am indexing documents that contain multiple locations. Nested within the
location property, there is a geo_point property called geo.

I would like to return results containing the calculated distance of the
nearest geo distance to a given lat/lon

{
mappings:{"clinicaltrial":{"properties":{
"armGroup":{"type":"string"},
"briefSummary":{"type":"string"},
"briefTitle":{"type":"string"},
"eligibility":{"type":"string", index:"not_analyzed"},
"condition":{"type":"string", index:"not_analyzed"},
"exclusionCriteria":{"type":"string", index:"not_analyzed"},
"firstReceivedDate":{"type":"string"},
"gender":{"type":"string"},
"id":{"type":"string", index:"not_analyzed"},
"inclusionCriteria":{"type":"string"},
"intervention":{
"properties":{
"intervention_name":{"type":"string",
index:"not_analyzed"},
"intervention_type":{"type":"string",
index:"not_analyzed"},
"description":{"type":"string"}
}
},
"keyword":{"type":"string", index:"not_analyzed"},
"lastChangedDate":{"type":"string"},
"location":{
"properties":{
"facility":{
"properties":{
"name":{"type":"string",
index:"not_analyzed"},
"address":{
"properties":{
"city":{"type":"string",
index:"not_analyzed"},
"state":{"type":"string",
index:"not_analyzed"},
"zip":{"type":"string",
index:"not_analyzed"},
"country":{"type":"string",
index:"not_analyzed"}
}
},
"geo":{
"type":"geo_point"
}
}
}
}
},
"maxAge":{"type":"long"},
"mboost":{"type":"long"},
"medicalGroup":{"type":"string"},
"minAge":{"type":"long"},
"phase":{"type":"string"},
"startDate":{"type":"string"},
"status":{"type":"string"},
"studyDesign":{"type":"string"},
"studyId":{"type":"string"},
"studyType":{"type":"string"},
"summary":{"type":"string"},
"title":{"type":"string"},
"type":{"type":"string"},
"verificationDate":{"type":"string"}}}}
}

In my query, I am using script_fields to compute distance, How can I modify
the query so that it returns the nearest computed distance from the
location array?

{"query":{
"custom_score":{
"query":{
"match_all":{}
},
"script":"_score + doc['mboost'].value"
}
}, "filter":{

"query":{
    "match_phrase":{
        "status":"Recruiting"
    }
}

}, "fields":"_source",
"script_fields":{
"distance":{
"params":{
"lat":42.3788774,
"lon":-72.032366
},
"script":"doc['location.facility.geo'].empty ? null :
doc['location.facility.geo'].distance(lat, lon)"
}
},
"sort":{
"_score":"desc"
}, "from":"0", "size":"10"
}

--
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.
For more options, visit https://groups.google.com/groups/opt_out.