def test_custom_index_class(self): class NoSourceIndex(Index): def search_query(self, *args, **kwargs): return (super(NoSourceIndex, self).search_query(*args, **kwargs).source(False)) cluster = Cluster(self.client, index_cls=NoSourceIndex) self.assert_expression(cluster['test'].search_query(), {"_source": False}) self.assert_expression(cluster['test'].search_query().source(None), {})
def test_index_compiler(self): cluster = Cluster(self.client, compiler=Compiler20()) index = Index(cluster, 'test') self.assert_expression( index.search_query(index.user.name == 'kimchy').filter( index.user.status == 0), { "query": { "bool": { "must": { "term": { "name": "kimchy" } }, "filter": { "term": { "status": 0 } } } } })
def cluster(client): yield Cluster( client, autodetect_es_version=False, compiler=DefaultCompiler )
def setUp(self): self.client = MagicMock() self.cluster = Cluster(self.client, compiler=DefaultCompiler) self.index = Index(self.cluster, 'test')
def es_cluster(es_client): return Cluster(es_client)
def setUp(self): self.client = MagicMock() self.cluster = Cluster(self.client) self.index = Index(self.cluster, 'test')
def cluster(client): yield Cluster(client)
from elasticsearch import Elasticsearch from elasticmagic import Cluster from elasticmagic import Document from elasticmagic import Field from elasticmagic.types import Text from elasticmagic.types import Integer es_client = Elasticsearch() es_cluster = Cluster(es_client) def get_es_product_index(settings): return es_cluster[settings['elasticsearch.product_index']] class ProductDoc(Document): __doc_type__ = 'product' name = Field(Text) status = Field(Integer)