# Function score query returned an invalid score: NaN or -Infinity

**URL:** <https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854>\
**Category:** Elasticsearch\
**Created:** [October 17, 2018, 1:55pm UTC](https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854 "2018-10-17T13:55:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunatic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lunatic/32/55516_2.png) [@lunatic](https://discuss.elastic.co/u/lunatic)\
**Post date:** [October 17, 2018, 1:55pm UTC](https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854/1 "2018-10-17T13:55:46Z")

</div>

I have a query using _function\_score_ and _field\_value\_factor_ like this:

```
GET my_item_list/doc/_search
{
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "field_value_factor": {
        "field": "sell_qty",
        "factor": 1.2,
        "missing": 1,
        "modifier": "ln1p"
      }
    }
  }
}

```

The query returns error like this:

```
    "error": {
    "root_cause": [
      {
        "type": "exception",
        "reason": "function score query returned an invalid score: NaN for doc: 189398"
      },
      {
        "type": "exception",
        "reason": "function score query returned an invalid score: NaN for doc: 230635"
      },
      {
        "type": "exception",
        "reason": "function score query returned an invalid score: NaN for doc: 978211"
      }
    ]

```

If I remove the "modifier": "ln1p" , the error disappears.  
The sell\_qty of the docs in id [189398,230635,978211] are all 0 but I set them to 1 if missing by setting:  
_"missing": 1_ in the query.

Mapping of the index:

```
{
  "my_item_list": {
    "mappings": {
      "doc": {
        "properties": {
          "act": {
            "type": "nested",
            "properties": {
              "id": {
                "type": "long"
              },
              "seq": {
                "type": "integer"
              }
            }
          },
          "area": {
            "type": "integer"
          },
          "ban": {
            "type": "integer"
          }
          "name": {
            "type": "text",
            "fields": {
              "en": {
                "type": "text"
              },
              "in": {
                "type": "text"
              }
            },
            "analyzer": "standard"
          },
          "price": {
            "type": "double"
          },
          "sell_qty": {
            "type": "integer"
          },
          "status": {
            "type": "byte"
          },
          "tag": {
            "type": "text",
            "fields": {
              "en": {
                "type": "text"
              },
              "in": {
                "type": "text"
              }
            },
            "analyzer": "standard"
          },
          "type": {
            "type": "byte"
          }
        }
      }
    }
  }
}

```

Could you please have a look? @dadoonet Thanks!

---

<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:** [October 18, 2018, 2:59pm UTC](https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854/2 "2018-10-18T14:59:16Z")

</div>

I don't understand why you are pinging @dadoonet directly? Yes, he is super awesome, but there are other folks on this forum that can help you too. 😉

I strongly suspect you have documents with a negative value for `sell_qty` in your index. You can find that out by running this query:

```auto
GET my_item_list/_search
{
  "query": {
    "range": {
      "sell_qty": {
        "lt": 0
      }
    }
  }
}

```

Any hit for that query is going to cause the error you are seeing.

---

<div class="post-metadata">

**Author:** ![lunatic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lunatic/32/55516_2.png) [@lunatic](https://discuss.elastic.co/u/lunatic)\
**Post date:** [October 19, 2018, 1:16am UTC](https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854/3 "2018-10-19T01:16:46Z")

</div>

Thanks, I fix this problem and there are negative values in my docs ...

PS: I thought dadoonet is good at lucene issues by old posts. 😜 Great thanks @abdon

---

<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:** [November 16, 2018, 1:25am UTC](https://discuss.elastic.co/t/function-score-query-returned-an-invalid-score-nan-or-infinity/152854/4 "2018-11-16T01:25:17Z")

</div>

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