elasticmock
elasticmock copied to clipboard
helpers.scan doesn't work
I'm trying to use elasticsearch.helpers.scan with the mocked ES. It apparently doesn't work because the results don't include a _scroll_id
: https://github.com/elastic/elasticsearch-py/blob/9fe0763670633848b521ff9df6350bc811f4f110/elasticsearch/helpers/init.py#L367. Is it insane to think about adding this functionality, or does that get way complicated?
Same here and I come to the same conclusion. Would you consider a PR in this direction?
Sorry guys, but I do not have too much time to maintain this library. But you can always send a PR with this improvement :)
You can mock the elastic search scan something like the below code
from elasticsearch_dsl import AttrDict
def mock_elasticsearch_scan():
class Search:
"""Dummy Search class
"""
def __init__(self):
pass
def scan(self):
yield AttrDict({
'x': 1,
'y': 1,
})
return Search()
_scroll_id
has been introduced in #17 . However, helpers.scan
is still broken.
The following trick seems to work
from elasticmock.fake_elasticsearch import FakeElasticsearch
def _mock_clear_scroll(client: FakeElasticsearch, *args, **kwargs):
# pylint: disable=unused-argument
pass
FakeElasticsearch.clear_scroll = _mock_clear_scroll