solr导入数据


solr数据导入,经过这几天的查资料,我觉得solr数据导入可以有三种方式:

1、编写数据xml文件,通过post.jar导入;

2、通过DIH导入;

3、利用solrj导入数据;

现针对第三种方式进行研究,在第一步中写了一段小的测试代码,可以参考:http://wiki.apache.org/solr/Solrj#Streaming_documents_for_an_update

具体的代码解释如下:

String url = "http://localhost:8080/solr";
HttpSolrServer server = new HttpSolrServer(url);
//If you wish to delete all the data from the index, do this 
//server.deleteByQuery( "*:*" );
//Construct a document 
SolrInputDocument doc1 = new SolrInputDocument();
   doc1.addField( "id", "id1_solrj" );
   doc1.addField( "type", "doc1_solrj" );
   doc1.addField( "name", "name1_solrj" );
   //Construct another document
   SolrInputDocument doc2 = new SolrInputDocument();
   doc2.addField( "id", "id2" );
   doc2.addField( "type", "doc2_solrj" );
   doc2.addField( "name", "name2_solrj" );
   //Create a collection of documents
   Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
   docs.add(doc1);
   docs.add(doc2);
   //Do a commit
   try {
    server.add(docs);
server.commit();
} catch (SolrServerException e) {
System.out.println("server commit error, error code:");
e.printStackTrace();
} catch (IOException e) {
System.out.println("server commit error, error code:");
e.printStackTrace();
}
}

该端代码执行后报异常:expect  mime type application/octet-stream but got text/html

没找到这个的解决办法,根据提示好像是说期望的类型和服务器反馈的类型不匹配

最后的解决办法是这样的:

之前在配置solr服务器的时候将solr解压路径\solr-4.8.1\example\solr下的solr.xml用\solr-4.8.1\example\multicore下的solr.xml文件进行了替换,目的是为了引入core0和core1,现在需要将这个动作进行回滚,并且修改collection1下的conf下的schema.xml文件,修改为对应的需要的列定义。然后执行以上的代码就不会产生问题。

原因我也不太明白,感觉应该是collection1的配置和core1、core0、乃至之前文章提到过的solrtest的配置应该不太一样。原因待查。不过现在已经可以通过客户端的方式将数据导入solr服务器,并在前端可以查询到相应的数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值