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!
This error occurs if:
"foo"
instead of 42
).schema.xml
, but your code sends a string.""
, "NaN"
, "NULL"
, "abc"
)schema.xml
.Example: For a field <field name="price" type="pfloat" .../>
, make sure you’re sending a valid float (e.g., 12.99
).
Validate Before Sending:
Reject or sanitize bad data before indexing.
Update Your Schema (If Needed):
schema.xml
accordingly.Otherwise, fix the source of the non-numeric data.
Handle Legacy or Unknown Data:
0
or omit the field, depending on your business logic.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.
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.