# Score 1 returned when querying geo\_point with value of NULL

**URL:** <https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048>\
**Category:** Elasticsearch\
**Created:** [May 28, 2019, 9:40am UTC](https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048 "2019-05-28T09:40:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan\_ml6](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@stan\_ml6](https://discuss.elastic.co/u/stan_ml6)\
**Post date:** [May 28, 2019, 9:40am UTC](https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048/1 "2019-05-28T09:40:21Z")

</div>

ElasticSearch returns a score of 1 when querying locations that have a NULL value for their location. While I would expect that when a location is NULL that the scoring function returns a value of 0.

Below I create an ElasticSearch index that contains a geo\_point and I insert one element that has a valid latitude and longitude and I insert another that has a null value for its location.

```
PUT my_index
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

PUT my_index/_doc/1
{
  "text": "Real location",
  "location": { 
    "lat": 41.12,
    "lon": -71.34
  }
}

PUT my_index/_doc/2
{
  "text": "NULL location",
  "location": null
}

```

The problem arises when I try to search with a scoring function (according to the documentation here: [https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-function-score-query.html)).

The real values will have a score between 0 and 1 (which is the expected behaviour), while the location with the NULL value will have a score of 1. I would expect it to be 0 since no location is given.

```
GET /hotels/_search/
{
  "query": {
    "function_score": {
      "functions": [
        {
          "gauss": {
            "location": {
              "origin": "41, -71",
              "scale": "10km"
            }
          }
        }
      ],
      "score_mode": "multiply"
    }
  }
}

```

How can I make sure that the score of elements with a NULL location is 0?

---

<div class="post-metadata">

**Author:** ![stan\_ml6](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@stan\_ml6](https://discuss.elastic.co/u/stan_ml6)\
**Post date:** [June 11, 2019, 2:34pm UTC](https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048/2 "2019-06-11T14:34:04Z")

</div>

bump

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [June 12, 2019, 2:12pm UTC](https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048/3 "2019-06-12T14:12:24Z")

</div>

The documentation states that if a value is missing the function will return 1 as the score: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#\_what\_if\_a\_field\_is\_missing](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_what_if_a_field_is_missing)

To work around this, you could add a function that checks whether there is a value for `location` and, using `"score_mode": "first"`, if there is not, assign a score of 0. Something like this:

```auto
GET my_index/_search/
{
  "query": {
    "function_score": {
      "functions": [
        {
          "filter": {
            "bool": {
              "must_not": {
                "exists": {
                  "field": "location"
                }
              }
            }
          },
          "weight": 0
        },
        {
          "gauss": {
            "location": {
              "origin": "41, -71",
              "scale": "10km"
            }
          }
        }
      ],
      "score_mode": "first"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 10, 2019, 2:12pm UTC](https://discuss.elastic.co/t/score-1-returned-when-querying-geo-point-with-value-of-null/183048/4 "2019-07-10T14:12:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
