The main QuerySet implementation. This provides the public API for the ORM.

Taken from django one and from django-elasticsearch.

class pyes.queryset.ESModel(index, type, es_url=None, es_kwargs={})
class pyes.queryset.QuerySet(model=None, using=None, index=None, type=None, es_url=None, es_kwargs={})

Represents a lazy database lookup for a set of objects.

agg(*args, **kwargs)
aggregate(*args, **kwargs)

Returns a dictionary containing the calculations (aggregation) over the current queryset

If args is present the expression is passed as a kwarg using the Aggregate object’s default alias.


Returns a new QuerySet that is a copy of the current one. This allows a QuerySet to proxy for a model manager in some cases.

annotate(*args, **kwargs)

Return a query set in which the returned objects have been annotated with data aggregated from related fields.

bulk_create(objs, batch_size=None)

Inserts each of the instances into the database. This does not call save() on each of the instances, does not send any pre/post save signals, and does not set the primary key attribute if it is an autoincrement field.


Returns a new QuerySet instance with filter_obj added to the filters.

filter_obj can be a Q object (or anything with an add_to_query() method) or a dictionary of keyword lookup arguments.

This exists to support framework features such as ‘limit_choices_to’, and usually it will be more natural to use other methods.


Performs a SELECT COUNT() and returns the number of records as an integer.

If the QuerySet is already fully cached this simply returns the length of the cached results set to avoid multiple SELECT COUNT(*) calls.


Creates a new object with the given kwargs, saving it to the database and returning the created object.

dates(field_name, kind, order='ASC')

Returns a list of datetime objects representing all available dates for the given field_name, scoped to ‘kind’.


Defers the loading of data for certain fields until they are accessed. The set of fields to defer is added to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case all deferrals are removed (None acts as a reset option).


Deletes the records in the current QuerySet.


Returns a new QuerySet instance that will select only distinct results.


Lets check if the queryset was already evaluated without accessing private methods / attributes

exclude(*args, **kwargs)

Returns a new QuerySet instance with NOT (args) ANDed to the existing set.

facet(*args, **kwargs)
filter(*args, **kwargs)

Returns a new QuerySet instance with the args ANDed to the existing set.

classmethod from_qs(qs, **kwargs)

Creates a new queryset using class cls using qs’ data.

  • qs – The query set to clone
  • kwargs – The kwargs to pass to _clone method
get(*args, **kwargs)

Performs the query and returns a single object matching the given keyword arguments.


Looks up an object with the given kwargs, creating one if necessary. Returns a tuple of (object, created), where created is a boolean specifying whether an object was created.


Returns a dictionary mapping each of the given IDs to the object with that ID.


An iterator over the results from applying this QuerySet to the database.


Returns the latest object, according to the model’s ‘get_latest_by’ option or optional given field_name.


Returns an empty QuerySet.


Essentially, the opposite of defer. Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated.


Returns a new QuerySet instance with the ordering changed.


Returns True if the QuerySet is ordered – i.e. has an order_by() clause or a default ordering on the model.


Reverses the ordering of the QuerySet.


Updates all elements in the current QuerySet, setting all the given fields to the appropriate values.


Selects which database this QuerySet should excecute its query against.

value_annotation = True
values_list(*fields, **kwargs)
pyes.queryset.generate_model(index, doc_type, es_url=None, es_kwargs={})
pyes.queryset.get_es_connection(es_url, es_kwargs)