SimplePostTool:警告:读取响应时出现IOException:java.io.IOException:服务器返回HTTP响应代码:400

时间:2018-02-11 15:21:26

标签: solr

我试图在命令提示符下使用以下命令将一些文档(json格式)发布到solr中,但我总是得到400 Bad Request错误。 JAVA_VERSION:1.8.0; Solr_Version:7.2

CMD:

C:\..\..\solr-7.2.1\example\exampledocs>java -Dtype=text/json -Durl=http://localhost:8983/solr/mycore/update -jar post.jar books.json

错误:

SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://localhost:8983/solr/mycore/update
SimplePostTool: WARNING: Response: {
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"This IndexSchema is not mutable.",
    "code":400}}
SimplePostTool: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:8983/solr/mycore/update
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/mycore/update...
Time spent: 0:00:00.062

我已在solrconfig.xml中添加了请求处理程序

<requestHandler name="/update" class="solr.UpdateRequestHandler" />

<schemaFactory class="ClassicIndexSchemaFactory"/> - &gt;用于引用schema.xml文件

Schema.xml :(为我的索引添加了新字段)

<field name="id" type="string" indexed="true" stored="true" required="true"  multiValued="false" />
<field name="_version_" type="plong" indexed="false" stored="false"/>
<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>  

<!-- new fields -starts -->
<field name="cat" type="text_general" indexed="true" stored="true"/>
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="price" type="pdouble" indexed="true" stored="true"/>
<field name="inStock" type="boolean" indexed="true" stored="true"/>
<field name="author" type="text_general" indexed="true" stored="true"/>
<!-- new fields -ends -->

我的唯一键是&#39; ID&#39;。

enter image description here

2 个答案:

答案 0 :(得分:0)

如果您开始使用无模式配置,则会为任何更新请求定义更新链。您必须为您删除that configuration to stop Solr from trying to automagically create fields(当您使用旧样式schema.xml时,这将无效。)

这是在solrconfig.xml文件中定义的,应该删除:

<initParams path="/update/**">
  <lst name="defaults">
    <str name="update.chain">add-unknown-fields-to-the-schema</str>
  </lst>
</initParams>

您不必删除链本身,只需删除更新路径的initParams。

答案 1 :(得分:0)

使用java -Dc = core_name -Dauto = yes -Dtype = application / json -jar post.jar * .json

我不知道它为什么起作用。