如何在文档到 SOLR 的批量更新处理中使用 SOLRJ ConcurrentUpdateSolrClient?

How do I use SOLRJ ConcurrentUpdateSolrClient in a batch update processing of docs to SOLR?

我正在尝试使用 SOLRJ 的 ConcurrentUpdateSolrClient 以批处理模式将许多文档添加到 Solr。我在 Solr-In-Action 中读到,使用这种模式比 HttpSolrClient 方法产生更好的性能。但是除了下面的内容之外,我找不到任何示例用法,这是用于查询而不是更新。非常感谢一个例子,说明这如何适合使用 Javabin 进行传输。至于批处理过程,我猜测它仍然与高级视图中的 HttpSolrClient 相同,通过调用许多 client.add(doc) 然后在某个时间调用 client.commit()。但是似乎没有任何好的例子,尽管我读过很多次它是向 Solr 添加批量文档的好方法。

   SolrClient client = new ConcurrentUpdateSolrClient.Builder("http://my-solr-server:8983/solr/core1").build();
   QueryResponse resp = client.query(new SolrQuery("*:*"));
 

感谢您提供的任何帮助。

我发现下面的代码有效,但仍然不确定是否仅此而已。 如果我有大量文档要添加到 Solr,也许在幕后,ConcurrentUpdateSolrClient 比 HttpSolrClient 更有效 运行。在设置客户端连接方面可能需要额外的参数,或者在添加文档之前需要其他客户端方法。

SolrClient client_concurrentupdate = new ConcurrentUpdateSolrClient.Builder("http://192.168.1.100:8983/solr/test").build();
      SolrInputDocument doc_concurrent = new SolrInputDocument();
      doc_concurrent.addField("id", "1");
      doc_concurrent.addField("name", "Test of concurrent add");
      client_concurrentupdate.add(doc_concurrent);
      client_concurrentupdate.commit();

从两种方法之间的测试来看,每种方法测试负载 1000 个小文档,并发方法所用时间为 429 毫秒,而 HTTP 方法所用时间为 1493 毫秒(在构建每个客户端后测量,因此结果用于创建文档、添加字段、添加文档和提交 1000 个文档块)。

因此,除了调用 Concurrent 方法来代替 HTTP 方法之外,似乎没有太多开箱即用的方法。但是,如果有人有其他答案或评论,我们将不胜感激。