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

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!

1 Like

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. :wink:

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:

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.

3 Likes

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. :stuck_out_tongue_winking_eye: Great thanks @abdon

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