Skip to content

Commit

Permalink
Merge pull request #36 from niaquinto/find-no-mapping
Browse files Browse the repository at this point in the history
Return no hits when trying to find one resource and no mapping exists
  • Loading branch information
petrjasek committed Jun 22, 2015
2 parents e41c3e3 + 452fe73 commit d22ad31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion eve_elastic/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ def find(self, resource, req, sub_resource_lookup):
query['aggs'] = source_config['aggregations']

args = self._es_args(resource)
hits = self.es.search(body=query, **args)
try:
hits = self.es.search(body=query, **args)
except elasticsearch.exceptions.RequestError as e:
if e.status_code == 400 and "No mapping found for" in e.error:
hits = {}
else:
raise
return self._parse_hits(hits, resource)

def find_one(self, resource, req, **lookup):
Expand Down
8 changes: 8 additions & 0 deletions eve_elastic/test/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,11 @@ def test_elastic_sort_by_score_if_there_is_query(self):
cursor = self.app.data.find('items', req, None)
self.assertEqual(2, cursor.count())
self.assertEqual('foo', cursor[0]['uri'])

def test_elastic_find_default_sort_no_mapping(self):
self.app.data.es.indices.delete_mapping(INDEX, '_all')
with self.app.test_request_context('/items/'):
req = parse_request('items')
req.args = {}
cursor = self.app.data.find('items', req, None)
self.assertEqual(0, cursor.count())

0 comments on commit d22ad31

Please sign in to comment.