HTTP 400: Bad Request

An HTTP 400 Bad Request can be caused by a variety of problems. However, it is generally a client-side issue. An HTTP 400 implies the problem is not with Solr, but rather with the request to Solr.

For example, if you have a schema.xml that defines a field with a particular field type, and then index a document with some other data type in that field, Solr will reject it with an HTTP 400. To put this into concrete terms, consider a very simple schema.xml:

<?xml version="1.0" encoding="UTF-8"?>
<schema name="demo" version="1.1">
  <types>
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="long" class="solr.TrieLongField" omitNorms="true"/>
  </types>
  <fields>
    <field name="id" type="string" indexed="true" stored="true" required="true"/>
    <field name="price" type="long" indexed="true" stored="true"/>
    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
  </fields>
  <uniqueKey>id</uniqueKey>
  <defaultSearchField>description</defaultSearchField>
  <solrQueryParser defaultOperator="OR"/>
</schema>

In this case, there is a price field that is expecting some long (numeric) data. Now suppose Solr receives a payload like this:

<add>
  <doc>
    <field name="id">something-1</field>
    <field name="price">zero</field>
  </doc>
</add>

This payload is telling Solr to store the string “zero” into a field that is supposed to have a numeric data type. When this happens, Solr responds with an HTTP 400.

Another common reason for this error is attempting to push data into a field that is not defined. Earlier versions of Solr do not support dynamic mapping (creating field definitions on the fly by analyzing incoming data). Using the example schema.xml above, imagine that Solr received a payload like this:

<add>
  <doc>
    <field name="id">something-1</field>
    <field name="available">true</field>
  </doc>
</add>

In this case, the available field is not defined in the schema.xml, and Solr doesn’t know how the data should be processed. It returns an HTTP 400 error in response.

The way to troubleshoot an HTTP 400 error is to read the response carefully and understand which part of the request is raising the exception. That will help you to identify a root cause and remediate.