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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步