async def test_get_connection():
    conn = create_connection()
    assert conn is get_connection()
    assert conn is get_connection('async')
    assert conn is connections.get_connection('async')

    with raises(KeyError):
        get_connection('default')
        connections.get_connection()
示例#2
0
    async def delete(self):
        """delete() executes the query by delegating to delete_by_query()"""
        aes = get_connection(self._using)

        response = await aes.delete_by_query(
            index=self._index,
            body=self.to_dict(),
            **self._params,
        )

        return AttrDict(response)
示例#3
0
    async def execute(self, ignore_cache=False):
        """
        Execute the search and return an instance of ``Response`` wrapping all
        the data.
        """
        if ignore_cache or not hasattr(self, '_response'):
            aes = get_connection(self._using)

            response = await aes.search(
                index=self._index,
                body=self.to_dict(),
                **self._params,
            )
            self._response = self._response_class(self, response)

        return self._response
示例#4
0
    async def count(self):
        """
        Return the number of hits matching the query and filters. Note that
        only the actual number is returned.
        """
        if hasattr(self, '_response') and self._response.hits.total.relation == 'eq':
            return self._response.hits.total.value

        aes = get_connection(self._using)
        d = self.to_dict(count=True)
        response = await aes.count(
            index=self._index,
            body=d,
            **self._params
        )
        return response['count']
示例#5
0
    async def scan(self):
        """
        Turn the search into a scan search and return a async generator that will
        iterate over all the documents matching the query.

        Use ``params`` method to specify any additional arguments you with to pass to the
        underlying ``scan`` helper
        """
        aes = get_connection(self._using)

        async for hit in scan(
                aes,
                query=self.to_dict(),
                index=self._index,
                **self._params
        ):
            yield self._get_result(hit)
async def test_get_with_configure():
    configure(dev={'host': 'localhost'})
    conn = get_connection('dev')
    assert isinstance(conn, AsyncElasticsearch)
async def test_create_connection_base():
    conn = create_connection()
    assert isinstance(conn, AsyncElasticsearch)
    assert conn is get_connection()