Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeSearch ignores attribute _source #53

Open
jankislinger opened this issue Dec 29, 2020 · 2 comments
Open

FakeSearch ignores attribute _source #53

jankislinger opened this issue Dec 29, 2020 · 2 comments

Comments

@jankislinger
Copy link
Contributor

When searching and keeping only selected attributes (using _source inside body) the fake search method ignores this and returns all attributes. This test fails but when run agains ES server (not the mock) the test passes. You can add this test to file ./tests/test_search.py.

    def test_correct_columns(self):
        self.es.index('index_for_search', doc_type=DOC_TYPE, body={'id': 1, 'data_x': 2, 'data_y': 'test'})
        body = {
            'query': {'term': {'id': 1}},
            '_source': ['id', 'data_x'],
        }
        response = self.es.search(index='index_for_search', doc_type=DOC_TYPE, body=body, _source=['id', 'data_x'])
        self.assertEqual(1, response['hits']['total'])
        doc = response['hits']['hits'][0]['_source']
        self.assertSetEqual({'id', 'data_x'}, set(doc))
@jankislinger
Copy link
Contributor Author

jankislinger commented Dec 29, 2020

Here's the first step to the solution. Please check it and let me know that I understand it correctly and whether that's the way to do it.

https://github.com/jankislinger/elasticmock/compare/master...jankislinger:select-fields

@vrcmarcos
Copy link
Owner

Humm I'm not too much into this library right now, just coordinating PR and releasing new versions. If this approach works for your use case without breaking any existent test, it should be good to go :)

Also, if you see any room for improvement in the library, go ahead! It would be awesome to have you on the maintainers' team! Wdyt about it? Are you willing to help maintain this library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants