@@ -307,6 +307,34 @@ async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
307307 )
308308 return item ["_source" ]
309309
310+ async def get_queryables_mapping (self , collection_id : str = "*" ) -> dict :
311+ """Retrieve mapping of Queryables for search.
312+
313+ Args:
314+ collection_id (str, optional): The id of the Collection the Queryables
315+ belongs to. Defaults to "*".
316+
317+ Returns:
318+ dict: A dictionary containing the Queryables mappings.
319+ """
320+ queryables_mapping = {}
321+
322+ mappings = await self .client .indices .get_mapping (
323+ index = f"{ ITEMS_INDEX_PREFIX } { collection_id } " ,
324+ )
325+
326+ for mapping in mappings .values ():
327+ fields = mapping ["mappings" ].get ("properties" , {})
328+ properties = fields .pop ("properties" , {}).get ("properties" , {}).keys ()
329+
330+ for field_key in fields :
331+ queryables_mapping [field_key ] = field_key
332+
333+ for property_key in properties :
334+ queryables_mapping [property_key ] = f"properties.{ property_key } "
335+
336+ return queryables_mapping
337+
310338 @staticmethod
311339 def make_search ():
312340 """Database logic to create a Search instance."""
@@ -535,8 +563,9 @@ def apply_stacql_filter(search: Search, op: str, field: str, value: float):
535563
536564 return search
537565
538- @staticmethod
539- def apply_cql2_filter (search : Search , _filter : Optional [Dict [str , Any ]]):
566+ async def apply_cql2_filter (
567+ self , search : Search , _filter : Optional [Dict [str , Any ]]
568+ ):
540569 """
541570 Apply a CQL2 filter to an Opensearch Search object.
542571
@@ -556,7 +585,7 @@ def apply_cql2_filter(search: Search, _filter: Optional[Dict[str, Any]]):
556585 otherwise the original Search object.
557586 """
558587 if _filter is not None :
559- es_query = filter .to_es (_filter )
588+ es_query = filter .to_es (await self . get_queryables_mapping (), _filter )
560589 search = search .filter (es_query )
561590
562591 return search
0 commit comments