The remote server returned an error: (400) Bad Request. when add docs to index

Benny picture Benny · Jan 6, 2011 · Viewed 10.6k times · Source

when i add docs to index, the page returns 400 bad request. And the solr has been start up and can get data from database. So i need put the data into index. However, it's failed always.


1) Here is code snippet of SolrBaseRepository

/// <summary>    
/// Base repository for Solr    
/// </summary>  
public class SolrBaseRepository  
{    
    /// <summary>    
    /// New instance of Solr    
    /// </summary>    
    /// <typeparam name="T">Specific type</typeparam>  
    public class Instance<T>    
    {    
        /// <summary>  
        /// Start Solr instance for a specific type  
        /// </summary>  
        public void Start()  
        {  
            var instances = Startup.Container.GetAllInstances(typeof (ISolrOperations<T>));  

            if (instances.Count() == 0)  
            {  
                Startup.Init<T>(Toolbox.SolrUrl);  
            }  
        }  

    }  
}  

2) here is main part of schemal.xml

<fields>    
    <field name="id" type="int" indexed="true" stored="true" required="true" />   
    <field name="firstname" type="text" indexed="true" stored="false"required="false" />   
    <field name="lastname" type="text" indexed="true" stored="false" required="false" />  
    <field name="position" type="text" indexed="true" stored="false" required="false" />  
    <field name="text" type="text" indexed="true" stored="false" multiValued="true" />  
</fields>  
<copyField source="firstname" dest="text" />    
<copyField source="lastname" dest="text" />    
<copyField source="position" dest="text" />    
<uniqueKey>id</uniqueKey>    
<defaultSearchField>text</defaultSearchField>    
<solrQueryParser defaultOperator="AND" />     

3) solrurl: http://localhost:8080/solr

<appSettings>  
<add key="SolrUrl" value="http://localhost:8080/solr"/>  
</appSettings>  

4) error is here:

/// <summary>  
/// Add all players to the index  
/// </summary>  
public void IndexPlayers()  
{  
    new SolrBaseRepository.Instance<Player>().Start();  

    var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Player>>();  
    var players = new PlayerRepository().GetPlayers();  

    **solr.Add(players);** // The remote server returned an error: (400) Bad Request.   
    solr.Commit();  
}  

Answer

Jokin picture Jokin · Jan 14, 2011

The solr log would give you the info that you need, or if you opened from console there should be an exception throw to the console.