diff --git a/api/views.py b/api/views.py index 8bbabc2..82ba760 100644 --- a/api/views.py +++ b/api/views.py @@ -100,13 +100,17 @@ def detail(request, name, id): if name not in ALLOWED_INDICES: return HttpResponse("This index doesn't exist!\n") es = Elasticsearch([settings.NODE1, settings.NODE2]) - results = es.search(index=name, q="_id:{}".format(id)) - if results['hits']['total'] == 0: - results = es.search(index=name, q="alternativeId:{}".format(id), - doc_type="_doc") - if results['hits']['total'] == 0: - results = es.search(index=name, q="biosampleId:{}".format(id), - doc_type="_doc") + result = es.get(index=name, id=id) + if result['found']: + results = {'hits': {'hits': [result]}} + else: + results = es.search(index=name, q="_id:{}".format(id)) + if results['hits']['total'] == 0: + results = es.search(index=name, q="alternativeId:{}".format(id), + doc_type="_doc") + if results['hits']['total'] == 0: + results = es.search(index=name, q="biosampleId:{}".format(id), + doc_type="_doc") return JsonResponse(results)