Add/Update (OVERWRITE=TRUE)
# Coding=utf-8import Requestsdata = {"Add": {"Doc": {"id": "10001", "Item_title": "I am a good person"}}} # The data to add params = {" Boost ": 1.0," Overwrite ":" true "," Commitwithin ": + # Overwrite: If there is already data for this ID in SOLR, overwrite it with url = '/http ' 127.0.0.1:8080/solr/collection1/update?wt=json ' # request urlheaders = {"Content-type": "Application/json"} # Request header (indicates that the content is in JSON format) R = Requests.post (URL, json = data, params = params, headers = headers) # Send request print (R.text) # {"Respo Nseheader ": {" status ": 0," Qtime ": 2}}
Inquire
Import Requestsitem = "I Am" # search field url = ' http://127.0.0.1:8080/solr/collection1/select?q=item_title: ' \%s ' &wt= Json&indent=true '%item # request url# verify=true-Check SSL certificate for a host R = Requests.get (URL, verify = False) # Send request, corresponding: R = <response [200]>r = R.json () # turns it into JSON format print (R) "" "{' Responseheader ': {' qtime ': 1, ' status ': 0, ' params ': {' Q ': ' item_title: ' \ \ I ' ', ' Indent ': ' true ', ' wt ': ' JSON '}, ' response ': {' numfound ': 1, ' Start ': 0, ' docs ': [{' _version_ ': 1597870382723891200, ' id ': ' 100001 ', ' item_title ': ' I'm a good person '}]}}numfound--how many related data--the query set returned (list) "" "
Python Operations SOLR Index Library