From 8aa9fb4b2f84cfd344abec06060358ad96dbc6c6 Mon Sep 17 00:00:00 2001 From: Jake Rosenberg Date: Mon, 16 Dec 2024 10:29:18 -0600 Subject: [PATCH] remove expensive prefix filter from Elasticsearch file queries (#1503) --- .../apps/api/datafiles/operations/tapis_operations.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/designsafe/apps/api/datafiles/operations/tapis_operations.py b/designsafe/apps/api/datafiles/operations/tapis_operations.py index 5d52b8ade..d3d0a687c 100644 --- a/designsafe/apps/api/datafiles/operations/tapis_operations.py +++ b/designsafe/apps/api/datafiles/operations/tapis_operations.py @@ -157,11 +157,13 @@ def search(client, system, path, offset=0, limit=100, query_string='', **kwargs) if not path.startswith('/'): path = '/' + path - if not path.endswith('/'): - path = path + '/' + + path = f"/{path.strip('/')}" + search = IndexedFile.search() search = search.query(ngram_query | match_query) - search = search.filter('prefix', **{'path._exact': path}) + if path != '/': + search = search.filter('term', **{'path._comps': path}) search = search.filter('term', **{'system._exact': system}) search = search.extra(from_=int(offset), size=int(limit)) res = search.execute() @@ -219,7 +221,7 @@ def mkdir(client, system, path, dir_name, *args, **kwargs): ------- dict """ - path_input = str(Path(path) / Path(dir_name)) + path_input = str(Path(path) / Path(dir_name)).rstrip(" ") client.files.mkdir(systemId=system, path=path_input)