solr cloud 之添加,删除,更新Document

阅读更多

 

    搭建完成solr cloud的集群之后,接下来的工作就是需要向集群中导入数据,之后可能要更新数据,或者删除数有,假设有有一个服务的schema中的field是这样定义的:

 


    
   
   
   
   

   

   新增记录

 

   首先可以通过最简便的方式向集群中添加数据,在cmd命令行中敲入以下命令:

 

java -Durl=http://localhost:8983/solr/update -jar   post.jar terminator.xml
   terminator.xml 文件的内容是:

 




  9999999
  abcdefghijkmn
  kkkkkkkkkkkkkkkkkkkkk
  
  gggggggggggggg
  llllllllllllllll
  quadquadquadquadquad
  geohashgeohashgeohashgeohashgeohashgeohash



  9999998
  abcdefghijkmn
  kkkkkkkkkkkkkkkkkkkkk
  
  gggggggggggggg
  llllllllllllllll
  quadquadquadquadquad
  geohashgeohashgeohashgeohashgeohashgeohash



  9999997
  abcdefghijkmn
  kkkkkkkkkkkkkkkkkkkkk
  
  gggggggggggggg
  llllllllllllllll
  quadquadquadquadquad
  geohashgeohashgeohashgeohashgeohashgeohash



  9999996
  abcdefghijkmn
  kkkkkkkkkkkkkkkkkkkkk
  
  gggggggggggggg
  llllllllllllllll
  quadquadquadquadquad
  geohashgeohashgeohashgeohashgeohashgeohash


 

 

成功执行命令:

 

D:\download\solr-4.1.0\solr-4.1.0\example\exampledocs>
java -Durl=http://localhost:8983/solr/update -jar post.jar terminator.xm
SimplePostTool version 1.5 Posting files to base url http://localhost:8983/solr/update using content-type application/xml..
POSTing file terminator.xml 1 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/update..

 Document的share规则:

通过以上命令,成功将4条记录插入到了集群中。在solr节点的查询页面进行查询,显示结果集如下:





  0
  3967
  
    *,[shard]
    true
    id:999999*
    xml
  


  
    9999999
    abcdefghijkmn
    kkkkkkkkkkkkkkkkkkkkk
    gggggggggggggg
    llllllllllllllll
    quadquadquadquadquad
    geohashgeohashgeohashgeohashgeohashgeohash
    1434087019164729344
    10.1.31.91:80/solr/collection1/
  
    9999998
    abcdefghijkmn
    kkkkkkkkkkkkkkkkkkkkk
    gggggggggggggg
    llllllllllllllll
    quadquadquadquadquad
    geohashgeohashgeohashgeohashgeohashgeohash
    1434087019165777920
    10.1.31.91:80/solr/collection1/
  
    9999997
    abcdefghijkmn
    kkkkkkkkkkkkkkkkkkkkk
    gggggggggggggg
    llllllllllllllll
    quadquadquadquadquad
    geohashgeohashgeohashgeohashgeohashgeohash
    1434087018344742912
    10.1.31.91:8983/solr/collection1/
  
    9999996
    abcdefghijkmn
    kkkkkkkkkkkkkkkkkkkkk
    gggggggggggggg
    llllllllllllllll
    quadquadquadquadquad
    geohashgeohashgeohashgeohashgeohashgeohash
    1434087018867982336
    10.1.31.91:8983/solr/collection1/

   大家会发现在输出的结果集上有一个[shard]字段,标识该条记录存储在集群中的哪个share分区中。要在结果集中shard字段可以通过设置 fl=*,[shard]做到。从[shard]属性的值来看四条记录被均匀的分布到了两个share中。

 

更新数据

删除数据

java -Ddata=args  -jar post.jar '9999996'

或者

java -Ddata=args  -jar post.jar 'id:9999996'

 

经过测试,以上两条命令都可以成功删除id为9999996的那条记录。

你可能感兴趣的:(solr cloud 之添加,删除,更新Document)