diff --git a/dcicutils/_version.py b/dcicutils/_version.py index 5fd75e6ee..df052d62f 100644 --- a/dcicutils/_version.py +++ b/dcicutils/_version.py @@ -1,4 +1,4 @@ """Version information.""" # The following line *must* be the last in the module, exactly as formatted: -__version__ = "0.3.3" +__version__ = "0.3.4" diff --git a/dcicutils/ff_utils.py b/dcicutils/ff_utils.py index bb5db9993..12766da19 100644 --- a/dcicutils/ff_utils.py +++ b/dcicutils/ff_utils.py @@ -331,9 +331,9 @@ def delete_field(obj_id, del_field, key=None, ff_env=None): return get_response_json(response) -def get_es_metadata(uuid, schema_name, es_client=None, key=None, ff_env=None): +def get_es_metadata(uuid, es_client=None, key=None, ff_env=None): """ - Given string item uuid and schema name (e.g. "file_fastq"), will return a + Given string item uuid, will return a dictionary response of the full ES ecord for that item (or an empty dictionary if the item doesn't exist/ is not indexed) You can pass in an Elasticsearch client (initialized by create_es_client) @@ -347,11 +347,16 @@ def get_es_metadata(uuid, schema_name, es_client=None, key=None, ff_env=None): health_res = authorized_request(auth['server'] + '/health', auth=auth, verb='GET') es_url = get_response_json(health_res)['elasticsearch'] es_client = es_utils.create_es_client(es_url, use_aws_auth=True) - try: - es_res = es_client.get(index=schema_name, doc_type=schema_name, id=uuid) - except TransportError: + es_res = es_client.search(index='_all', body={'query': {'term': {'_id': uuid}}}) + es_hits = es_res['hits']['hits'] + if not isinstance(es_hits, list): + raise Exception('ERROR malformed results found when searching for uuid %s' % uuid) + elif len(es_hits) > 1: + raise Exception('ERROR multiple results found when searching for uuid %s' % uuid) + elif len(es_hits) == 0: return {} - return es_res.get('_source', {}) + # es_hits should only be length 1, so this is the result + return es_hits[0] ##################### diff --git a/test/test_ff_utils.py b/test/test_ff_utils.py index 6feeb5e13..a9273601b 100644 --- a/test/test_ff_utils.py +++ b/test/test_ff_utils.py @@ -336,7 +336,7 @@ def test_get_es_metadata(integrated_ff): from dcicutils import es_utils # use this test biosource test_item = '331111bc-8535-4448-903e-854af460b254' - res = ff_utils.get_es_metadata(test_item, 'biosource', key=integrated_ff['ff_key']) + res = ff_utils.get_es_metadata(test_item, key=integrated_ff['ff_key']) assert res['uuid'] == test_item assert res['item_type'] == 'biosource' assert isinstance(res['embedded'], dict) @@ -348,7 +348,7 @@ def test_get_es_metadata(integrated_ff): auth=integrated_ff['ff_key']) es_url = ff_utils.get_response_json(health_res)['elasticsearch'] es_client = es_utils.create_es_client(es_url, use_aws_auth=True) - res2 = ff_utils.get_es_metadata(test_item, 'biosource', es_client=es_client, + res2 = ff_utils.get_es_metadata(test_item, es_client=es_client, key=integrated_ff['ff_key']) assert res2['uuid'] == res['uuid']