API Reference¶
Client¶
- pyramid_es.client_from_config(settings, prefix='elastic.')[source]¶
Instantiate and configure an Elasticsearch from settings.
- pyramid_es.get_client(request)[source]¶
Get the registered Elasticsearch client. The supplied argument can be either a Request instance or a Registry.
- class pyramid_es.client.ElasticClient(servers, index, timeout=1.0, disable_indexing=False)[source]¶
A handle for interacting with the Elasticsearch backend.
- analyze(text, analyzer)[source]¶
Preview the result of analyzing a block of text using a given analyzer.
- delete_mapping(cls)[source]¶
Delete the mapping corresponding to cls on the server. Does not delete subclass mappings.
- ensure_all_mappings(base_class, recreate=False)[source]¶
Initialize explicit mappings for all subclasses of the specified SQLAlcehmy declarative base class.
- ensure_index(recreate=False)[source]¶
Ensure that the index exists on the ES server, and has up-to-date settings.
- ensure_mapping(cls, recreate=False)[source]¶
Put an explicit mapping for the given class if it doesn’t already exist.
- get(obj, routing=None)[source]¶
Retrieve the ES source document for a given object or (document type, id) pair.
- index_document(id, doc_type, doc, parent=None)[source]¶
Add or update the indexed document from a raw document source (not an object).
Model Mixin¶
Utility classes intended to make it easier to specify Elastic Search mappings for model objects.
- class pyramid_es.mixin.ESField(name, filter=None, attr=None, **kwargs)[source]¶
A leaf property that doesn’t emit a mapping definition.
This behavior is useful if you want to allow Elastic Search to automatically construct an appropriate mapping while indexing.
- class pyramid_es.mixin.ESMapping(*args, **kwargs)[source]¶
ESMapping defines a tree-like DSL for building Elastic Search mappings.
Calling dict(es_mapping_object) produces an Elastic Search mapping definition appropriate for pyes.
Applying an ESMapping to another object returns an Elastic Search document.
Queries¶
- class pyramid_es.query.ElasticQuery(client, classes=None, q=None)[source]¶
Represents a query to be issued against the ES backend.
- add_facet(*args, **kwargs)[source]¶
Add a query facet, to return data used for the implementation of faceted search (e.g. returning result counts for given possible sub-queries).
The facet should be supplied as a dict in the format that ES uses for representation.
It is recommended to use the helper methods add_term_facet() or add_range_facet() where possible.
- add_range_facet(name, field, ranges)[source]¶
Add a range facet.
ES will return data about documetn counts for the top sub-queries (by document count) inw hich the results are filtered by a given numerical range.
- add_term_facet(name, size, field)[source]¶
Add a term facet.
ES will return data about document counts for the top sub-queries (by document count) in which the results are filtered by a given term.
- count()[source]¶
Execute this query to determine the number of documents that would be returned, but do not actually fetch documents. Returns an int.
- filter_terms(*args, **kwargs)[source]¶
Filter for documents where the field term matches one of the elements in value (which should be a sequence).
- filter_value_lower(*args, **kwargs)[source]¶
Filter for documents where term is numerically more than lower.
- filter_value_upper(*args, **kwargs)[source]¶
Filter for documents where term is numerically less than upper.
- static match_all_query()[source]¶
Static method to return a filter dict which will match everything. Can be overridden in a subclass to customize behavior.
- order_by(*args, **kwargs)[source]¶
Sort results by the field key. Default to ascending order, unless desc is True.
- size(*args, **kwargs)¶
When returning results, stop at document n.
- start(*args, **kwargs)¶
When returning results, start at document n.
- pyramid_es.query.filters(f)[source]¶
A convenience decorator to wrap query methods that are adding filters. To use, simply make a method that returns a filter dict in elasticsearch’s JSON object format.
Should be used inside @generative (listed after in decorator order).
- pyramid_es.query.generative(f)[source]¶
A decorator to wrap query methods to make them automatically generative.