如何在solrj中使用solr的所有核心
How to use all the cores of Solr in solrj
我已经下载了 solr 5.2.0 并开始使用 $solr_home/bin/solr
start
日志指出:
等着看Solr监听8983端口[/]
在端口 8983 (pid=17330
) 上启动了 Solr 服务器。搜索愉快!
然后我访问了 http://localhost:8983/solr
并使用 Core Admin / new Core 创建了一个新核心作为 Core1(使用 solr-5.2.0/server/solr/configsets/data_driven_schema_configs/config
作为新核心)
然后我写了一个 java 索引一些记录的代码
代码如下:
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core1"); //$NON-NLS-1
//HttpSolrClient solrClient = new HttpSolrClient(args[0]); //$NON-NLS-1
// Empty the database...
solrClient.deleteByQuery( "*:*" );// delete everything! //$NON-NLS-1$
System.out.println("cleared"); //$NON-NLS-1$
ArrayList<SolrInputDocument> docs = new ArrayList<>();
long starttime = System.currentTimeMillis();
for (int i = 0; i < 1000000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("bat", "book"+i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("name", "The Legend of the Hobbit part 1 " + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id1", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("name1", "The Legend of the Hobbit part 2 " + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id2", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
docs.add(doc);
if (i % 250000 == 0) {
solrClient.add(docs);
System.out.println("added "+ i + "documents"); //$NON-NLS-1$ //$NON-NLS-2$
docs.clear();
}
}
solrClient.add(docs);
System.out.println("completed adding to Solr. Now commiting.. Please wait"); //$NON-NLS-1$
solrClient.commit();
long endtime = System.currentTimeMillis();
System.out.println("process completed in "+(endtime-starttime)/1000+" seconds"); //$NON-NLS-1$ //$NON-NLS-2$
}
在 运行 代码之后,我检查
http://localhost:8983/solr/#/~cores/core1
并看到 1000000 个文档被编入索引。
然后我添加了另一个核心(以与核心 1 类似的方式命名为 core2),然后再次 运行 工作,这次,我看到核心 2 没有显示任何文件,只有核心 1 仍然显示。
任何人都可以建议如何使用 solr 的两个核心来分发和存储文档,以便我可以更快地索引数据,我的假设是如果我增加核心数量,索引速度应该增加。
如果有人尝试并成功地利用了两个内核并看到了性能改进,请告诉我。
谢谢。
在您的代码中,它仍然指向 core1。
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core1"
如果你想要 core2 的 indexex
这里需要改一下
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core2"
此更改后尝试 运行 作业,它将为 core2 建立索引。
我已经下载了 solr 5.2.0 并开始使用 $solr_home/bin/solr
start
日志指出:
等着看Solr监听8983端口[/]
在端口 8983 (pid=17330
) 上启动了 Solr 服务器。搜索愉快!
然后我访问了 http://localhost:8983/solr
并使用 Core Admin / new Core 创建了一个新核心作为 Core1(使用 solr-5.2.0/server/solr/configsets/data_driven_schema_configs/config
作为新核心)
然后我写了一个 java 索引一些记录的代码
代码如下:
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core1"); //$NON-NLS-1
//HttpSolrClient solrClient = new HttpSolrClient(args[0]); //$NON-NLS-1
// Empty the database...
solrClient.deleteByQuery( "*:*" );// delete everything! //$NON-NLS-1$
System.out.println("cleared"); //$NON-NLS-1$
ArrayList<SolrInputDocument> docs = new ArrayList<>();
long starttime = System.currentTimeMillis();
for (int i = 0; i < 1000000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("bat", "book"+i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("name", "The Legend of the Hobbit part 1 " + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id1", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("name1", "The Legend of the Hobbit part 2 " + i); //$NON-NLS-1$ //$NON-NLS-2$
doc.addField("id2", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
docs.add(doc);
if (i % 250000 == 0) {
solrClient.add(docs);
System.out.println("added "+ i + "documents"); //$NON-NLS-1$ //$NON-NLS-2$
docs.clear();
}
}
solrClient.add(docs);
System.out.println("completed adding to Solr. Now commiting.. Please wait"); //$NON-NLS-1$
solrClient.commit();
long endtime = System.currentTimeMillis();
System.out.println("process completed in "+(endtime-starttime)/1000+" seconds"); //$NON-NLS-1$ //$NON-NLS-2$
}
在 运行 代码之后,我检查 http://localhost:8983/solr/#/~cores/core1 并看到 1000000 个文档被编入索引。
然后我添加了另一个核心(以与核心 1 类似的方式命名为 core2),然后再次 运行 工作,这次,我看到核心 2 没有显示任何文件,只有核心 1 仍然显示。
任何人都可以建议如何使用 solr 的两个核心来分发和存储文档,以便我可以更快地索引数据,我的假设是如果我增加核心数量,索引速度应该增加。
如果有人尝试并成功地利用了两个内核并看到了性能改进,请告诉我。
谢谢。
在您的代码中,它仍然指向 core1。
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core1"
如果你想要 core2 的 indexex
这里需要改一下
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/core2"
此更改后尝试 运行 作业,它将为 core2 建立索引。