Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr - How to fix "Error adding field ... msg=For input string" when post data to core

Tags:

solr

I am new to Solr. I created a Solr(8.1.0) core using SolrCloud for testing, and try to post data as a json file.

When an object has a value with float like "spalte412": "35.5" or with special characters, it throws an error in the in the console:

SimplePostTool: WARNING: Response: {
  "responseHeader":{
    "rf":2,
    "status":400,
    "QTime":223},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","java.lang.NumberFormatException"],
    "msg":"ERROR: [doc=52] Error adding field 'spalte421'='156.6' msg=For input string: \"156.6\"",
    "code":400}}

I tried to edit core Schema by adding the field, in the Admin UI, without success.

Thanks for you help !

like image 204
Emile Avatar asked Mar 31 '26 07:03

Emile


1 Answers

If you're not pre-defining your fields, the field types determined for the field will depend on the first document submitted that has that field present. Solr uses this field type to guess the type of the field, and in this case the guessed field type differs from the format you're sending in later documents.

The schemaless mode is neat for prototyping, but when moving to production you should always add the fields up front with the correct types so you don't suddenly get any surprises (as above) when the documents are submitted in a different order (or different documents) than when developing.

You can define fields in schema.xml or through the SchemaAPI.

like image 159
MatsLindh Avatar answered Apr 02 '26 22:04

MatsLindh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!