以下是我的代码:
HttpPost postRequest = new HttpPost("http://localhost:8983/solr/core1/update/json?wt=json&commit=true");
StringEntity entity = new StringEntity("{\n"
+ " \"id\": \"1\",\n"
+ " \"title\": \"Doc 1\"\n"
+ "}", "UTF-8");
entity.setContentType("application/json");
postRequest.setEntity(entity);
HttpResponse response = httpClient.execute(postRequest);
但是当我尝试将 Json 添加到 Solr 5.5.0 时,出现了以下异常:
{"responseHeader":{"status":400,"QTime":2},"error":{"metadata":["error-class","org.apache.solr.common。 SolrException","root-error-class","org.apache.solr.common.SolrException"],"msg":"Unknown command 'id' at [9]","code":400}}
最佳答案
在不同的 Solr 版本中,有一些关于处理 json 的更改/错误修复,但这里最好的办法就是接受错误消息给你的提示,并采取相应的行动。
Solr 需要一个“命令”,所以您应该将您的文档包含在一个“添加”元素中,这样字符串看起来像这样:
{
"add": {
"doc": {
"id": "1",
"title":"Doc 1"
}
}
}
这应该行得通
关于java - 将 json 插入 solr 5.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43994187/