solr客户端的使用


1:添加

 

 2查询

  

 

 3:删除:

  

 

删除两种方法:

1、根据id删除:

<delete>

<id>test001</id>

</delete>

<commit/>

2、根据查询删除:

<delete>

<query>*:*</query>

</delete>

<commit/>

   二使用java代码:实现功能

     

    @Test
    public void addDoc() throws SolrServerException, IOException{
        //创建一个连接
        //单机版
        SolrServer solrServer=new HttpSolrServer("http://192.168.100.91:8080/solr");
        //集群版
        //SolrServer solrServer2=new CloudSolrServer("");
        //创建一个文档对象
        SolrInputDocument document=new SolrInputDocument();
        document.addField("id", "test001");
        document.addField("item_title", "测试商品");
        
        //把文档写入索引库
        solrServer.add(document);
        //提交
        solrServer.commit();
    }
    @Test
    public void delDoc() throws SolrServerException, IOException{
        //创建一个连接
        SolrServer solrServer=new HttpSolrServer("http://192.168.100.91:8080/solr");
        solrServer.deleteById("test001");
        //提交
        solrServer.commit();
    }

     

  
  

 

 

 

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM