elasticmock icon indicating copy to clipboard operation
elasticmock copied to clipboard

helpers.scan doesn't work

Open tdhopper opened this issue 6 years ago • 4 comments

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?

tdhopper avatar May 09 '18 15:05 tdhopper

Same here and I come to the same conclusion. Would you consider a PR in this direction?

anneschuth avatar Sep 25 '18 13:09 anneschuth

Sorry guys, but I do not have too much time to maintain this library. But you can always send a PR with this improvement :)

vrcmarcos avatar Oct 03 '18 20:10 vrcmarcos

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

mohantyashish109 avatar Oct 07 '19 13:10 mohantyashish109

_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

limjcst avatar Oct 21 '21 03:10 limjcst