solrj 创建solr core
时间: 2024-05-12 11:18:24 浏览: 216
1.4、solrj的使用_代码开始1
好的,关于solrj创建solr core的问题,首先需要确保你已经在你的Java项目里添加了solrj的dependency。然后,你可以通过以下代码来创建solr core:
```java
String solrUrl = "http://localhost:8983/solr";
HttpSolrClient solrClient = new HttpSolrClient.Builder(solrUrl).build();
CoreAdminRequest.Create createCoreRequest = new CoreAdminRequest.Create();
createCoreRequest.setCoreName("new_core_name");
createCoreRequest.setInstanceDir("new_core_instance_dir");
CoreAdminResponse response = createCoreRequest.process(solrClient);
if (response.getStatus() == 0) {
System.out.println("Core created successfully!");
} else {
System.err.println("Failed to create core!");
System.exit(1);
}
```
这段代码创建了一个名为"new_core_name"的solr core,并将它的实例目录设置为"new_core_instance_dir"。如果成功创建solr core,控制台会输出"Core created successfully!",否则输出"Failed to create core!"。
阅读全文