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 of42). - 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
-
Check Your Data:
- Verify that the value sent to Solr matches the numeric type defined in
schema.xml. - Example: For a field
<field name="price" type="pfloat" .../>, make sure you’re sending a valid float (e.g.,12.99).
- Verify that the value sent to Solr matches the numeric type defined in
-
Validate Before Sending:
- Implement input validation in your application or ETL pipeline.
- Reject or sanitize bad data before indexing.
-
Update Your Schema (If Needed):
- If the field should accept text, not numbers, update your
schema.xmlaccordingly. - Otherwise, fix the source of the non-numeric data.
- If the field should accept text, not numbers, update your
-
Handle Legacy or Unknown Data:
- Clean up legacy datasets or add migration scripts to convert values.
- Default bad values to
0or 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.

