1) 命令解釋apache
curl 'localhost:8983/solr/update?commit=true' -H 'Contenttype:application/json' -d '[{"id":"book1","user":{"add":"jack"}}]'json
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"/>app
參考:
curl
Apache Solr Documentation
ide
Schema REST APIui