SolrException: Invalid Number for field

Errors

The Error

You are indexing documents and Solr rejects them with:

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

This means you sent a value that is not a valid number into a field that expects a number. Solr cannot turn "hello" into an integer, so it drops the entire document.


What Is Actually Happening

Your schema says a field is numeric (like pint, pfloat, plong, pdouble), but your application is sending something that is not a number — a string, an empty value, "NaN", "NULL", or garbage data.

NUMERIC FIELD TYPE MISMATCHValues Solr Accepts423.14-100099.99Values That Cause the Error"foo""""NaN""NULL""$5"Solr drops the ENTIRE document — not just the bad fieldOne bad value in one field means the whole document is rejected


Common Scenarios

1. Empty or Null Values

Your data pipeline sends "" (empty string) or "null" for a numeric field. Solr cannot parse these as numbers.

2. Currency Symbols or Units

Values like "$19.99", "150kg", or "100%" contain non-numeric characters. Strip those before indexing.

3. Legacy or Dirty Data

Old records from a database migration, CSV import, or third-party API may contain unexpected values like "N/A", "TBD", or "unknown" in what should be numeric fields.

4. Schema Mismatch

The field was recently changed from text_general to pfloat in the schema, but old data still exists in the index, or the application was not updated to send proper numbers.


How to Fix It

Fix 1: Clean Your Data Before Indexing

Validate every value before sending it to Solr. If a field is numeric, make sure the value is actually a number:

// PHP example
$price = is_numeric($rawPrice) ? (float)$rawPrice : null;
if ($price !== null) {
    $doc['price'] = $price;
}
// Do not send the field at all if it is not a valid number
# Python example
try:
    doc['price'] = float(raw_price)
except (ValueError, TypeError):
    pass  # skip the field entirely

Fix 2: Change the Schema to Match Your Data

If the field genuinely receives mixed data (sometimes numbers, sometimes text), change the field type in your schema.xml to text_general or string instead of a numeric type.

<!-- If the field can contain non-numeric values -->
<field name="price" type="string" indexed="true" stored="true"/>

Note: this means you lose numeric sorting and range queries on that field.

Important: After changing a field type, you must reset your index data — delete all existing documents and re-index everything from scratch. The old indexed data was built with the previous field type and is incompatible. In your Opensolr Control Panel: upload the updated schema.xml, click Reload, then click Reset Data, and re-index all your content.

Fix 3: Handle Empty Values

If your application sometimes sends empty values, either:

  • Do not send the field when the value is empty
  • Set a default value in your schema: <field name="price" type="pfloat" default="0" .../>

How to Find the Bad Data

Check your Error Log in the Opensolr control panel. The error message tells you exactly:

  • Which field received the bad value
  • What the bad value was (in quotes)
  • Which document was being processed (if the ID is included)

Look for lines like:

SolrException: Invalid Number: "foo" for field price

Then search your source data for that value and fix it at the source.


Quick Checklist

  • Check the Error Log — it shows the exact field and bad value
  • Validate data before sending to Solr — is_numeric(), float(), parseInt()
  • Remove currency symbols, units, and non-numeric characters before indexing
  • Handle empty/null values — either skip the field or set a schema default
  • If the field truly needs mixed data, change the schema type to string

Still seeing Invalid Number errors? Reach out to us at support@opensolr.com with the error details — we will help you track down the bad data.