Documentation > Errors in Solr > SolrException: Invalid Number for field

SolrException: Invalid Number for Field

Overview

When indexing data in Solr, you may encounter the following error:

ERROR (qtp123456-78) [<replica>] o.a.s.h.RequestHandlerBase org.apache.solr.common.SolrException: Invalid Number: <bad value> for field <numeric field>

This message means Solr attempted to index a value into a numeric field (such as int, float, double, or long), but the provided value wasn’t a valid number. When this happens, Solr will drop the entire document from the index—so this error is no joke!


Why Does This Happen?

This error occurs if:

  • Non-numeric data is sent to a numeric field (e.g., "foo" instead of 42).
  • Your application code or data pipeline is generating or passing bad values.
  • There is legacy or inconsistent data sneaking through.
  • There’s a schema mismatch—maybe the field is defined as numeric in schema.xml, but your code sends a string.

Common Scenarios

  • Null, empty, or malformed values in incoming data (e.g., "", "NaN", "NULL", "abc")
  • Data imported from legacy systems or third parties
  • Changes in business logic or code that alter value formatting

How to Fix It

  1. Check Your Data:
  2. Verify that the value sent to Solr matches the numeric type defined in schema.xml.
  3. Example: For a field <field name="price" type="pfloat" .../>, make sure you’re sending a valid float (e.g., 12.99).

  4. Validate Before Sending:

  5. Implement input validation in your application or ETL pipeline.
  6. Reject or sanitize bad data before indexing.

  7. Update Your Schema (If Needed):

  8. If the field should accept text, not numbers, update your schema.xml accordingly.
  9. Otherwise, fix the source of the non-numeric data.

  10. Handle Legacy or Unknown Data:

  11. Clean up legacy datasets or add migration scripts to convert values.
  12. Default bad values to 0 or omit the field, depending on your business logic.

Best Practices

  • Always validate your data before indexing.
  • Use Solr’s Schema Browser or Analysis tool to check field types.
  • Log and monitor failed documents—don’t let errors slip by unnoticed.

Sample Error & Diagnosis

Sample Error Log:

org.apache.solr.common.SolrException: Invalid Number: "foo" for field price

Diagnosis: - Field: price (expected: float) - Value received: "foo" (invalid)

Resolution:
Update your application logic to ensure only numeric values are sent for the price field.


Still Stuck?

Don’t sweat it—sometimes even the best code lets a gremlin slip through.
If you keep running into this issue or can’t locate the source, contact OPENSOLR support for expert help.






Review us on Google Business
ISO-9001 CERTIFIED ISO-27001 CERTIFIED