批量导入数据到solr中

创建配置文件,配置solr模板和solr服务器地址


	
	
	
	
		
	

批量导入
	 public void importItemData(){
        TbItemExample example=new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andStatusEqualTo("1");
        List tbItems = itemMapper.selectByExample(example);
        System.out.println("===商品开始===");
        for (TbItem item : tbItems) {
            Map specMap = JSON.parseObject(item.getSpec());
            item.setSpecMap(specMap);
            System.out.println(item);
        }
        solrTemplate.saveBeans(tbItems);
        solrTemplate.commit();
        System.out.println("===商品结束===");

    }

	public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("classpath*:spring/applicationContext*.xml");
        SolrUtil solrUtil = (SolrUtil) context.getBean("solrUtil");
        solrUtil.importItemData();
    }
批量删除
	public void delete(){
        Query query = new SimpleQuery("*:*");
        solrTemplate.delete(query);
        solrTemplate.commit();
    }

 	public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("classpath*:spring/applicationContext*.xml");
        SolrUtil solrUtil = (SolrUtil) context.getBean("solrUtil");
        solrUtil.delete();
    }

你可能感兴趣的:(批量导入数据到solr中)