1) 命令解释

curl 'localhost:8983/solr/update?commit=true' -H 'Contenttype:application/json' -d '[{"id":"book1","user":{"add":"jack"}}]'

update: command
commit=true: 更新后提交,可查
add: 表示添加(对应字段可以包含多个值)

2) 更新
curl '192.168.15.31:8983/solr/update?commit=true' -H 'Contenttype:
application/json' -d '[{"id":"1","file":{"set":"New file name"}}]'
set:  更新一个字段
注意:不能直接set不存在的字段,可以借助动态字段添加(如ISBN_s, _s表示是动态字段),动态字段似乎不能索引?

curl http://192.168.15.31:8983/solr/update?commit=true -H 'Content-type:application/json' -d '[
    {"id"        : "book2",
     "cat"       : { "add" : "myself" },
     "pubyear_i" : { "set" : 2002 },
     "ISBN_s"    : { "set" : "0-380-97365-2"}
    }
   ]'
2.1) 按照id删除
curl http://192.168.15.31:8983/solr/update?commit=true -H 'Content-type:application/json' -d '
    {"delete"        : "book1"
    }
   '
删除多个:
curl http://192.168.15.31:8983/solr/update?commit=true -H 'Content-type:application/json' -d '
    {"delete"        : ["book1","book2"]
    }
   '   
3) 查找
http://192.168.15.31:8983/solr/select?q=id:book1&indent=true&wt=json&fl=author,title
solr: application name
select: request handler
q=id:book1: 查询id为book1的文档
wt=json:表示返回格式是json   
fl=author,title: 返回的字段

查找id为book1的结果
{
  "responseHeader":{
    "status":0,
    "QTime":16,
    "params":{
      "fl":"author,title",
      "indent":"true",
      "q":"id:book1",
      "wt":"json"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "title":["American Gods"],
        "author":"Neil Gaiman"}]
  }}   
 
4) 增加字段(字段名字为hanhuili)
vi example/solr/collection1/conf/schema.xml

 <field name="hanhuili" type="text_general" indexed="true" stored="true"/>

参考:

Apache Solr Documentation

Schema REST API



posted on 2014-12-06 14:38  #hanhui  阅读(108)  评论(0编辑  收藏  举报