elasticmock
elasticmock copied to clipboard
FakeSearch ignores attribute _source
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))
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
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?