# Function\_score with nested geo\_location

**URL:** <https://discuss.elastic.co/t/function-score-with-nested-geo-location/24976>\
**Category:** Elasticsearch\
**Created:** [July 6, 2015, 7:07pm UTC](https://discuss.elastic.co/t/function-score-with-nested-geo-location/24976 "2015-07-06T19:07:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rhbecker](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@rhbecker](https://discuss.elastic.co/u/rhbecker)\
**Post date:** [December 2, 2016, 3:28am UTC](https://discuss.elastic.co/t/function-score-with-nested-geo-location/24976/2 "2016-12-02T03:28:53Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html) provides enough examples to make the approach clear:

```auto
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](https://discuss.elastic.co/t/nested-value-on-function-score/29935/2), 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:

```auto
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?**

---

_[View the full topic](https://discuss.elastic.co/t/function-score-with-nested-geo-location/24976)._
