`
qindongliang1922
  • 浏览: 2146619 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7265517b-f87e-3137-b62c-5c6e30e26109
证道Lucene4
浏览量:116304
097be4a0-491e-39c0-89ff-3456fadf8262
证道Hadoop
浏览量:124574
41c37529-f6d8-32e4-8563-3b42b2712a50
证道shell编程
浏览量:58443
43832365-bc15-3f5d-b3cd-c9161722a70c
ELK修真
浏览量:70340
社区版块
存档分类
最新评论

curl操作Solr5.1.0增删改查

    博客分类:
  • Solr
阅读更多
1,使用curl查询结果,并转成csv保存


curl http://localhost:8983/solr/company/query -d '
q=*:*&
start=500&
rows=300&
sort=modifyTime asc&
fl=cpyName&
wt=csv'  | sed '1d' >> csv


2,使用curl查询一个关键词
curl -s  http://localhost:8983/solr/company/query -d '
q=sname:'$1'&
rows=0'

3,添加一个文档doc:
curl http://localhost:8983/solr/demo/update -d '
[
 {"id" : "book1",
  "title_t" : "The Way of Kings",
  "author_s" : "Brandon Sanderson"
 }
]'

4,获取一个文档:
curl http://localhost:8983/solr/demo/get?id=book1
{
  "doc": {
    "id" : "book1",
    "author_s": "Brandon Sanderson",
    "title_t" : "The Way of Kings",
    "_version_": 1410390803582287872
  }
}

5,更新一个文档:
curl http://localhost:8983/solr/demo/update -d '
[
 {"id"         : "book1",
  "cat_s"      : { "add" : "fantasy" },
  "pubyear_i"  : { "add" : 2010 },
  "ISBN_s"     : { "add" : "978-0-7653-2635-5" }
 }
]'


6,以CSV形式,添加一批文档:
$ curl http://localhost:8983/solr/demo/update?commitWithin=5000 -H 'Content-type:text/csv' -d '
id,cat_s,pubyear_i,title_t,author_s,series_s,sequence_i,publisher_s
book1,fantasy,2010,The Way of Kings,Brandon Sanderson,The Stormlight Archive,1,Tor
book2,fantasy,1996,A Game of Thrones,George R.R. Martin,A Song of Ice and Fire,1,Bantam
book3,fantasy,1999,A Clash of Kings,George R.R. Martin,A Song of Ice and Fire,2,Bantam
book4,sci-fi,1951,Foundation,Isaac Asimov,Foundation Series,1,Bantam
book5,sci-fi,1952,Foundation and Empire,Isaac Asimov,Foundation Series,2,Bantam
book6,sci-fi,1992,Snow Crash,Neal Stephenson,Snow Crash,,Bantam
book7,sci-fi,1984,Neuromancer,William Gibson,Sprawl trilogy,1,Ace
book8,fantasy,1985,The Black Company,Glen Cook,The Black Company,1,Tor
book9,fantasy,1965,The Black Cauldron,Lloyd Alexander,The Chronicles of Prydain,2,Square Fish
book10,fantasy,2001,American Gods,Neil Gaiman,,,Harper'


7,查询一批数据,返回每行数据的:关键词,查询耗时,命中数量,示例数据如下:
"连云港通裕天然气有限公司"
"连云港市天缘食品有限公司"
"重庆市涪陵国有资产投资经营集团有限公司" 


查询脚本如下:
curl -s  http://localhost:8983/solr/webpage/query -d '
q=content:'$1'&
rows=0'

批处理脚本如下:
执行这个批处理的查询脚本,测下平均耗时:
#for line in `cat csv | head -n 3`
for line in `cat csv`
do
echo $line  `sh kw_query.sh  $line   |   tr -d '\r\n' | gawk -F, '{print $2,$5}' | gawk -F: '{print $2,$4 }' | gawk -F" " '{print $1,$3}'`
done

结果如下:
"连云港通裕天然气有限公司" 283 7
"连云港市天缘食品有限公司" 137 2
"重庆市涪陵国有资产投资经营集团有限公司" 15 8


参考资料:http://yonik.com/


最后欢迎大家扫码关注微信公众号:我是攻城师(woshigcs),我们一起学习,进步和交流!(woshigcs)
本公众号的内容是有关搜索和大数据技术和互联网等方面内容的分享,也是一个温馨的技术互动交流的小家园,有什么问题随时都可以留言,欢迎大家来访!



0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics