File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -461,6 +461,13 @@ impl OpenSearchQueryBuilder {
461
461
. collect ( )
462
462
}
463
463
464
+ /// # Panics
465
+ ///
466
+ /// This function will panic if:
467
+ ///
468
+ /// * The structure of the JSON query is not as expected (e.g., missing keys or incorrect types).
469
+ ///
470
+ /// Ensure that the input data and the structure of the query are valid and correctly handled.
464
471
pub fn construct_payload ( & self , indexes : & [ SearchIndex ] ) -> QueryResult < Vec < Value > > {
465
472
let mut query_obj = Map :: new ( ) ;
466
473
let mut bool_obj = Map :: new ( ) ;
@@ -500,10 +507,13 @@ impl OpenSearchQueryBuilder {
500
507
Ok ( indexes
501
508
. iter ( )
502
509
. map ( |index| {
503
- let updated_query = self . replace_status_field (
504
- query[ "query" ] [ "bool" ] [ "filter" ] . as_array ( ) . unwrap ( ) ,
505
- index,
506
- ) ;
510
+ let updated_query = query. get ( "query" )
511
+ . and_then ( |q| q. get ( "bool" ) )
512
+ . and_then ( |b| b. get ( "filter" ) )
513
+ . and_then ( |f| f. as_array ( ) )
514
+ . map ( |filters| self . replace_status_field ( filters, index) )
515
+ . unwrap_or_default ( ) ;
516
+
507
517
let mut final_query = Map :: new ( ) ;
508
518
final_query. insert ( "bool" . to_string ( ) , json ! ( { "filter" : updated_query } ) ) ;
509
519
You can’t perform that action at this time.
0 commit comments