From 1604fa35bd10964acb32cf5c374c373f3d11e961 Mon Sep 17 00:00:00 2001 From: Hans Kallekleiv <16436291+HansKallekleiv@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:33:33 +0200 Subject: [PATCH] Use term filter instead of match for exact keyword matches when finding grid data uuids in elastic search (#681) --- .../services/sumo_access/queries/grid3d.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/backend_py/primary/primary/services/sumo_access/queries/grid3d.py b/backend_py/primary/primary/services/sumo_access/queries/grid3d.py index 3d0b51e14..f9f4ab2cb 100644 --- a/backend_py/primary/primary/services/sumo_access/queries/grid3d.py +++ b/backend_py/primary/primary/services/sumo_access/queries/grid3d.py @@ -78,23 +78,23 @@ async def get_grid_geometry_and_property_blob_ids_async( { "bool": { "must": [ - {"match": {"_sumo.parent_object.keyword": case_id}}, - {"match": {"class": "cpgrid"}}, - {"match": {"fmu.iteration.name": iteration}}, - {"match": {"fmu.realization.id": realization}}, - {"match": {"data.name.keyword": grid_name}}, + {"term": {"_sumo.parent_object.keyword": case_id}}, + {"term": {"class.keyword": "cpgrid"}}, + {"term": {"fmu.iteration.name.keyword": iteration}}, + {"term": {"fmu.realization.id": realization}}, + {"term": {"data.name.keyword": grid_name}}, ] } }, { "bool": { "must": [ - {"match": {"_sumo.parent_object.keyword": case_id}}, - {"match": {"class": "cpgrid_property"}}, - {"match": {"fmu.iteration.name": iteration}}, - {"match": {"fmu.realization.id": realization}}, - {"match": {"data.name.keyword": parameter_name}}, - {"match": {"data.tagname.keyword": grid_name}}, + {"term": {"_sumo.parent_object.keyword": case_id}}, + {"term": {"class.keyword": "cpgrid_property"}}, + {"term": {"fmu.iteration.name.keyword": iteration}}, + {"term": {"fmu.realization.id": realization}}, + {"term": {"data.name.keyword": parameter_name}}, + {"term": {"data.tagname.keyword": grid_name}}, ] } }, @@ -102,7 +102,6 @@ async def get_grid_geometry_and_property_blob_ids_async( "minimum_should_match": 1, } } - time_filter = get_time_filter(parameter_time_or_interval_str) if time_filter.time_type != TimeType.NONE: @@ -118,7 +117,6 @@ async def get_grid_geometry_and_property_blob_ids_async( result = response.json() hits = result["hits"]["hits"] - if len(hits) != 2: raise InvalidDataError(f"Expected 2 hits, got {len(hits)}", service=Service.SUMO)