Solr returned an error #400 (Bad Request) for url

I am using Solr 6.5.0, and I came across a scenario where I have to index a data field which may of multiple languages in the document.

I am trying to use a separate field for each language and I have to index the data of specific language to the corresponding field defined for that language.

I have added below config and schema changes:

Solr config:

  <requestHandler name="/update" class="solr.UpdateRequestHandler">
       <lst name="defaults">
         <str name="update.chain">langid</str>
       </lst>    
    </requestHandler>
    <updateRequestProcessorChain name="langid">
         <processor class="org.apache.solr.update.processor.TikaLanguageIdentifierUpdateProcessorFactory">
           <str name="langid.fl">title</str>
           <str name="langid.langField">lang</str>
           <str name="langid.fallback">en</str>
         </processor>
         <processor class="solr.LogUpdateProcessorFactory" />
         <processor class="solr.RunUpdateProcessorFactory" />
       </updateRequestProcessorChain>

schema:

<field name="code" type="string" indexed="true" stored="true"/>
    <field name="title" type="string" indexed="true" stored="true"/>
    <field name="content_english" type="text_english" indexed="true" stored="true"/>
    <field name="content_french" type="text_french" indexed="true" stored="true"/>
    <field name="content_spanish" type="text_spanish" indexed="true" stored="true"/>

Input xml:

<add>
<doc>
  <field name="code">one</field>
  <field name="title">Adventures</field>
  <field name="content_english">Especially the fuzzy search is very welcome; Solr really is a beautiful engine and it’s incredibly fast: millions of documents are no problem. Of course, if your servers capacities are configured correctly.</field>    
</doc>
<doc>
  <field name="code">two</field>
  <field name="title">Aventures</field>
  <field name="content_french">Surtout la recherche floue est très bienvenue; Solr est vraiment un beau moteur et c'est incroyablement rapide: des millions de documents ne posent aucun problème. Bien sûr, si les capacités de vos serveurs sont configurées correctement.</field>    
</doc>
<doc>
  <field name="code">three</field>
  <field name="title">Aventuras</field>
  <field name="content_spanish">Especialmente la búsqueda difusa es muy bienvenida; Solr realmente es un motor hermoso y es increíblemente rápido: millones de documentos no son ningún problema. Por supuesto, si las capacidades de los servidores están configuradas correctamente.</field>    
</doc>
</add>

whenever I update the core, I'am getting the below error:

C:solr-6.5.0exampleexampledocs>java
-Durl=http://localhost:8983/solr/autodetect/update?update.chain=langid -jar post.jar multilanguage.xml SimplePostTool version 5.0.0 

Posting files to [base] url http://localhost:8983/solr/autodetect/update?update.chain=langid using content-type application/xml... POSTing file multilanguage.xml to [base] SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://localhost:8983/solr/autodetect/update?update.chain=langid SimplePostTool: WARNING: Response: 4006org.apache.solr.common.SolrExceptionorg.apache.solr.common.SolrExceptionDocument is missing mandatory uniqueKey field: id400 SimplePostTool: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:8983/solr/autodetect/update?update.chain=langid 1 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/autodetect/update?update.chain=langid... Time spent: 0:00:00.179


Error : ID field is missing from your documents.

id which is used to identify each document uniquely is specified in schema file like below.

<uniqueKey>id</uniqueKey>  

Every document must and should have field which specified as uniquekey.

Include Id field for all your docs and check. ex:

<doc>
  <field name="id">001</field>
  <field name="code">one</field>
  <field name="title">Adventures</field>
  <field name="content_english">Especially the fuzzy search is very welcome; Solr really is a beautiful engine and it’s incredibly fast: millions of documents are no problem. Of course, if your servers capacities are configured correctly.</field>    
</doc>

Well have you looked at the error? Your documents don't have a value for the mandatory field called 'id'. You either have to give each one an id:

<add>
<doc>
  <field name="code">one</field>
  <field name="id">1</field>
  <field name="title">Adventures</field>
  <field name="content_english">Especially the fuzzy search is very welcome; Solr really is a beautiful engine and it’s incredibly fast: millions of documents are no problem. Of course, if your servers capacities are configured correctly.</field>    
</doc>
<doc>
  <field name="code">two</field>
  <field name="id">2</field>
  <field name="title">Aventures</field>
  <field name="content_french">Surtout la recherche floue est très bienvenue; Solr est vraiment un beau moteur et c'est incroyablement rapide: des millions de documents ne posent aucun problème. Bien sûr, si les capacités de vos serveurs sont configurées correctement.</field>    
</doc>
<doc>
  <field name="code">three</field>
  <field name="id">3</field>
  <field name="title">Aventuras</field>
  <field name="content_spanish">Especialmente la búsqueda difusa es muy bienvenida; Solr realmente es un motor hermoso y es increíblemente rápido: millones de documentos no son ningún problema. Por supuesto, si las capacidades de los servidores están configuradas correctamente.</field>    
</doc>
</add>

Or you can configure Solr to automatically assign a value if one isn't present.

链接地址: http://www.djcxy.com/p/67046.html

上一篇: 如何检索和查询Apache Solr 6.5中的JSON类型字段

下一篇: Solr为url返回了一个错误#400(错误请求)