pyes.queryset

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.

aggs
all()

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.

complex_filter(filter_obj)

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.

count()

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.

create(**kwargs)

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’.

defer(*fields)

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).

delete()

Deletes the records in the current QuerySet.

distinct(*field_names)

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

evaluated()

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.

exists()
facet(*args, **kwargs)
facets
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.

Parameters:
  • 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.

get_or_create(**kwargs)

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.

in_bulk(id_list)

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

index
iterator()

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

latest(field_name=None)

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

none()

Returns an empty QuerySet.

only(*fields)

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.

order_by(*field_names)

Returns a new QuerySet instance with the ordering changed.

ordered

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

reverse()

Reverses the ordering of the QuerySet.

size(number)
start(number)
type
update(**kwargs)

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

using(alias)

Selects which database this QuerySet should excecute its query against.

value_annotation = True
values(*fields)
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)