Skip to main content

An ORM Client library for SolrCloud

Project description


Latest Version Travis CI Build Status Coveralls Coverage Status

Wukong offers an ORM query engine for Solr and Solr Cloud.


	pip install wukong


Create Solr Collection

Before you use wukong, make sure you already created your collection on SolrCloud. For example,

	curl http://localhost:8080/solr/admin/collections?action=CREATE&name=users&numShards=1&replicationFactor=2

A sample schema can be like:

  	<field name="id" type="int" indexed="true" stored="true" required="true" />
	<field name="name" type="string" indexed="true" stored="true" required="true"/>
	<field name="city" type="string" indexed="true" stored="true"/>
	<field name="age" type="int" indexed="true" stored="true"/>

Create a model class for Solr collection

Create a class for your Solr collection by extending the class SolrDoc. For example,

from wukong.models import SolrDoc

class User(SolrDoc):
    collection_name = "users"
    solr_hosts = "localhost:8080,localhost:8081"

    def validate_schema_fields(self, fields):

    def get_data_for_solr(self):

You can overide existing methods to fit your business logic, like validate_schema_fields, get_data_for_solr.

Use Solr QueryManger

Creat a document

User.documents.create(User_id=12345, name="Test Name", city="Test City")

Update a document

User.documents.update(User_id=12345, name="Test Name")

To index a batch of documentsto your Solr collection, use the container class: SolrDocs. Instead of accessing SOLR multiple times, it only issues one request to SOLR, which is more efficient.

	docs = [
		User(User_id=12345, name="Test Name1", city="Test Cit1"),
		User(User_id=123456, name="Test Name2", city="Test City2")
	docs = SolrDocs(docs)

Fetch a document


Fetch multiple documents

User.documents.filter(name__eq="Test Name", city__wc="Test*").all()

Use compounded logic

User.documents.filter(OR(city__wc="Test*", name__eq="Test Name"))

Sort by a field


Force only return a certain fields

User.documents.only("is", "name").all()

Force only return the top 10 documents


Chain the query methods


Delete a document


Batch delete documents

User.documents.filter(name__eq="Test Name").all().delete()


Detailed docs can be found at

#Release Notes


  • Catch RequestsException Instead Of Connection Errors To Allow For Retries during timeouts (#30)


  • search(): actually send the query_dict in the request body as was intended in 1.0.0 (missed a cherry-pick)


  • Removed support for Python versions < 3.5 and pypy
  • Use POST instead of GET for /select API calls in order to avoid exceeding the max uri length for long queries (#26)


  • Only add /solr/ to the end of a solr url if it isn't already there


  • Simplify the method of making requests, and add logging so it's more visible what's happening (#18)
  • Don't log debugging messages as error messages (#19)
  • Broaden Travis support (#17)
  • Make sure a scheme is always on the solr request (#20)


  • Add ability to update extraparams like omitHeader for solr requests


  • Collection alias support


  • Fix zookeeper cluster state unicode issue


  • Zookeeper states for Solr 6
  • handle situations with unknown Solr hostnames
  • support stats in the query for Solr 6


  • Add support for Python 3.x


  • initial version for wukong

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wukong-1.1.0.tar.gz (16.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page