循环查询一个列表中词的个数:
#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