I'm looking to do something very similar (but with a date, rather than a location). The original poster laid out a very good example mapping and document set, so I'll ask my questions based on that.
My goal is to return a set of documents based on a query that references properties at the document root, then apply a decay-based function score to the resulting set, but using a nested object property.
If I remove the nesting from the equation by adding a nonnested_geo_location
property to the document root, exactly like locations.geo_location
, in terms of mapping and values, the function score documentation page provides enough examples to make the approach clear:
GET my_index/_search
{
"query": {
"function_score": {
"query": {
"match": {
"name": "doe"
}
},
"functions": [
{
"gauss": {
"nonnested_geo_location": {
"origin": { "lat": 42, "lon": -88 },
"scale": "100km"
}
}
}
]
}
}
}
By way of examples provided in an answer to a different question, I was able to figure out how to apply the decay function scoring based on a nested object property, but without a query first running to potentially narrow the set of documents to which the scoring is applied:
GET /my_index/_search
{
"_source": ["name", "locations"],
"query": {
"nested": {
"path": "locations",
"query": {
"function_score":{
"functions": [
{
"gauss": {
"locations.geo_location": {
"origin": { "lat": 42, "lon": -88 },
"scale": "100km"
}
}
}
]
}
}
}
}
}
I've been unable to find any examples that marry these 2 needs. How do I formulate a query that references properties from the parent object in order to narrow the set of documents to which a decay function score that references a nested object property is then applied?