55
66async def get_grid_names (sumo_client : SumoClient , case_id : str , iteration : str ) -> List [str ]:
77 """Get a list of grid names for a case and iteration"""
8- query = {
8+ payload = {
99 "size" : 0 ,
1010 "query" : {
1111 "bool" : {
@@ -25,7 +25,7 @@ async def get_grid_names(sumo_client: SumoClient, case_id: str, iteration: str)
2525 }
2626 },
2727 }
28- response = await sumo_client .post_async ("/search" , json = query )
28+ response = await sumo_client .post_async ("/search" , json = payload )
2929
3030 result = response .json ()
3131 grid_names = result .get ("aggregations" ).get ("grid_names" ).get ("buckets" )
@@ -38,7 +38,7 @@ async def get_grid_geometry_checksums(
3838 sumo_client : SumoClient , case_id : str , iteration : str , grid_name : str
3939) -> List [str ]:
4040 """Get a list of checksums for a grid geometry in a case and iteration"""
41- query = {
41+ payload = {
4242 "size" : 0 ,
4343 "query" : {
4444 "bool" : {
@@ -59,7 +59,7 @@ async def get_grid_geometry_checksums(
5959 }
6060 },
6161 }
62- response = sumo_client .post_async ("/search" , json = query )
62+ response = sumo_client .post_async ("/search" , json = payload )
6363
6464 result = response .json ()
6565 checksums = result .get ("aggregations" ).get ("checksums" ).get ("buckets" )
@@ -75,18 +75,25 @@ async def get_grid_geometry_blob_id(
7575 grid_name : str ,
7676) -> str :
7777 """Get the blob id for a given grid geometry in a case, iteration and realization"""
78- response = await sumo_client .get_async (
79- "/search" ,
80- query = f"_sumo.parent_object:{ case_id } AND \
81- class.keyword:cpgrid AND \
82- fmu.iteration.name:{ iteration } AND \
83- fmu.realization.id:{ realization } AND \
84- data.name.keyword:{ grid_name } " ,
85- size = 1000 ,
86- select = "_id" ,
87- )
88-
89- hits = response ["hits" ]["hits" ]
78+ payload = {
79+ "query" : {
80+ "bool" : {
81+ "must" : [
82+ {"match" : {"_sumo.parent_object.keyword" : case_id }},
83+ {"match" : {"class" : "cpgrid" }},
84+ {"match" : {"fmu.iteration.name" : iteration }},
85+ {"match" : {"fmu.realization.id" : realization }},
86+ {"match" : {"data.name.keyword" : grid_name }},
87+ ]
88+ }
89+ },
90+ "size" : 1 ,
91+ }
92+ response = await sumo_client .post_async ("/search" , json = payload )
93+
94+ result = response .json ()
95+ hits = result ["hits" ]["hits" ]
96+ print (hits )
9097 if len (hits ) != 1 :
9198 raise ValueError (f"Expected 1 hit, got { len (hits )} " )
9299 return [hit ["_id" ] for hit in hits ][0 ]
@@ -101,19 +108,25 @@ async def get_grid_parameter_blob_id(
101108 parameter_name : str ,
102109) -> str :
103110 """Get the blob id for a given grid parameter in a case, iteration and realization""" ""
104- response = await sumo_client .get_async (
105- "/search" ,
106- query = f"_sumo.parent_object:{ case_id } AND \
107- class.keyword:cpgrid_property AND \
108- fmu.iteration.name:{ iteration } AND \
109- fmu.realization.id:{ realization } AND \
110- data.name.keyword:{ parameter_name } AND \
111- data.tagname.keyword:{ grid_name } " ,
112- size = 1000 ,
113- select = "_id" ,
114- )
115-
116- hits = response ["hits" ]["hits" ]
111+ payload = {
112+ "query" : {
113+ "bool" : {
114+ "must" : [
115+ {"match" : {"_sumo.parent_object.keyword" : case_id }},
116+ {"match" : {"class" : "cpgrid_property" }},
117+ {"match" : {"fmu.iteration.name" : iteration }},
118+ {"match" : {"fmu.realization.id" : realization }},
119+ {"match" : {"data.name.keyword" : parameter_name }},
120+ {"match" : {"data.tagname.keyword" : grid_name }},
121+ ]
122+ }
123+ },
124+ "size" : 1 ,
125+ }
126+ response = await sumo_client .post_async ("/search" , json = payload )
127+
128+ result = response .json ()
129+ hits = result ["hits" ]["hits" ]
117130
118131 if len (hits ) != 1 :
119132 raise ValueError (f"Expected 1 hit, got { len (hits )} " )
@@ -158,18 +171,23 @@ async def get_nx_ny_nz_for_ensemble_grids(
158171 sumo_client : SumoClient , case_uuid : str , iteration : str , grid_name : str
159172) -> List [List [int ]]:
160173 """Get a list of nxnynz for all realizations of a grid model in a case and iteration"""
174+ payload = {
175+ "query" : {
176+ "bool" : {
177+ "must" : [
178+ {"match" : {"_sumo.parent_object.keyword" : case_uuid }},
179+ {"match" : {"class" : "cpgrid" }},
180+ {"match" : {"fmu.iteration.name" : iteration }},
181+ {"match" : {"data.name.keyword" : grid_name }},
182+ ]
183+ }
184+ },
185+ "size" : 1000 ,
186+ }
161187
162- response = await sumo_client .get_async (
163- "/search" ,
164- query = f"_sumo.parent_object:{ case_uuid } AND \
165- class.keyword:cpgrid AND \
166- fmu.iteration.name:{ iteration } AND \
167- data.name.keyword:{ grid_name } " ,
168- size = 1000 ,
169- select = "data" ,
170- )
171-
172- hits = response ["hits" ]["hits" ]
188+ response = await sumo_client .post_async ("/search" , json = payload )
189+ result = response .json ()
190+ hits = result ["hits" ]["hits" ]
173191
174192 nxnynz = []
175193 for hit in hits :
0 commit comments