python对solr进行查询、插入操作(GET\POST)

循环查询一个列表中词的个数:

#coding=utf-8
import requests
ls = [u'', u'', u'一个', u'天才', u'', u'也是']
for item in ls:
    url = 'http://*IP*:8985/solr/*集合名*/select?q=*字段名*:"\%s"&wt=json&indent=true'%item
    r = requests.get(url, verify = False)
    r = r.json()['response']['numFound']
    print item +":"+ str(r)

插入一条数据:

复制代码
#coding=utf-8
import json
import requests

data = {"add":{ "doc":{"id":"100001","*字段名*":u"我是一个大好人"}}}
params = {"boost":1.0,"overwrite":"true","commitWithin":1000}
url = 'http://*IP*:8985/solr/*集合名*/update?wt=json'
headers = {"Content-Type": "application/json"}
r = requests.post(url, json = data, params = params, headers = headers)
print r.text
复制代码

 

posted @   右介  阅读(3933)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示