使用 solrj 客户端,您可以创建 SolrInputDocument 对象并将它们发布到 SolrServer 实例,无论是 HttpSolrServer 还是 EmbeddedSolrServer。SolrInputDocument 是一个名称值对集合,相当于您尝试发布的 json。如https://wiki.apache.org/solr/Solrj#Adding_Data_to_Solr 所述
如果您真的想将 JSON 发送到 Solr 服务器,您可以使用类似 HTTPClient 的东西将 JSON 发布到http://solrHost.com:8983/solr/update/json。
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://solrHost.com:8983/solr/update/json");
StringEntity input = new StringEntity("{\"firstName\":\"Bob\",\"lastName\":\"Williams\"}");
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8717 次 |
| 最近记录: |