【问题标题】:"msg":"[doc=null] missing required field: id","code":400}"msg":"[doc=null] 缺少必填字段:id","code":400}
【发布时间】:2016-06-23 12:12:49
【问题描述】:

当我在通过 java 代码索引时将 json 对象发布到 apache solr 6 时,我收到如下错误:

错误信息如下:

"{"元数据":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.common.SolrException"],"味精“:”[文档=空] 缺少必填字段:id","code":400}}"

我的json对象如下:

"_childDocuments_" :[    
    {
      "entityname": "ReportDuplicate"
    }
  ],
"_childDocuments_" :[    
    {
      "entityname": "LinkedReport"
    }
  ],    

"_childDocuments_" :[    
    {
      "entityname": "Source"
    }
  ],
"_childDocuments_" :[
    {
      "entityname": "Literature",
"_childDocuments_" :[
        {
          "entityname": "Authors"
        }
      ]
    }
  ],
"_childDocuments_" :[

    {
      "entityname": "AdditionalInformation"
    }
  ],

我发布 json 对象的 java 代码如下:

org.apache.http.client.HttpClient client = HttpClientBuilder.create().build();

                HttpPost post = new HttpPost("http://localhost:8983/solr/icsr/update/json?wt=json&commit=true");
                StringEntity entity  = new StringEntity("{\"add\": { \"doc\":"+value+" }}", "UTF-8");

                entity.setContentType("application/json");
                post.setEntity(entity);                
                HttpResponse response = client.execute(post);
                HttpEntity httpEntity = response.getEntity();
                InputStream in = httpEntity.getContent();

                String encoding = httpEntity.getContentEncoding() == null ? "UTF-8" : httpEntity.getContentEncoding().getName();
                encoding = encoding == null ? "UTF-8" : encoding;
                String responseText = IOUtils.toString(in, encoding);
                System.out.println("response Text is " + responseText);

我正在使用 solr 6 服务器来索引来自 java 代码的数据: 由于我在调试时遇到错误的 HTTP 请求并且我是 solr 的新手, 并且在 managed-schema.xml 文件中没有进行任何更改: 提前谢谢

【问题讨论】:

    标签: apache solr


    【解决方案1】:

    Solr 总是接受2016-06-20T14:54:27.734Z 格式的日期(这是一个例子)。 仅以这种格式发送日期 YYYY-MM-DDThh:mm:ssZ ,其中

    YYYY 是年份。 MM 是月份。 DD 是一个月中的一天。 hh 是一天中的小时,如 24 小时制。 mm 是分钟。 ss 是秒。 Z 是一个文字 'Z' 字符,表示该日期的字符串表示形式为 UTC

    以这种格式发送日期。这将 100% 工作!如果这对您有帮助,请告诉我。

    【讨论】:

    • 我只能接受一个答案..我尝试接受两个但我不能。
    • 好吧,我的错 :) 我忘了,那是一个不同的答案。我这边的错误
    • 索引错误的日期...虽然索引输入日期是 1993-06-20,但在 solr 响应中,日期变为“1993-06-19T18:30:00Z”,变化是在日期...任何解决方案
    • 您在哪个系统上编制索引?看起来像一个时区问题。我试过了,它对我来说很好。
    • 我将时区设置为 "UTC" 是我的错误。而不是我的语言环境或默认设置
    【解决方案2】:

    检查您的schema.xml 文件。必须有一个像

    这样的声明
    <field name="id" type="string" multiValued="false" required="true" stored="true"/>
    

    您可以设置 required=true ,在索引文档时也提供它的 id,或者只是设置 required=false ,它将 100% 工作!如果对您有帮助,请告诉我。

    【讨论】:

    • 当我设置 required=true 在 Apache solrs 管理页面中出现以下错误:schema:org.xml.sax.SAXParseException; systemId:solrres:/托管模式;行号:2;列号:6;不允许匹配“[xX][mM][lL]”的处理指令目标。
    • 您是否将 id 发送到索引?
    • 当您设置 required=true 时,请确保您在 json 中发送“id”字段以进行索引。
    • 谢谢 ...当我设置 required=false 我的问题得到解决并且也没有将属性 indexed..设置为“id”字段
    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多