Skip to content

Commit f0ff3e0

Browse files
committed
fix: clippy errors
1 parent becd05e commit f0ff3e0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

crates/analytics/src/opensearch.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ impl OpenSearchQueryBuilder {
461461
.collect()
462462
}
463463

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.
464471
pub fn construct_payload(&self, indexes: &[SearchIndex]) -> QueryResult<Vec<Value>> {
465472
let mut query_obj = Map::new();
466473
let mut bool_obj = Map::new();
@@ -500,10 +507,13 @@ impl OpenSearchQueryBuilder {
500507
Ok(indexes
501508
.iter()
502509
.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+
507517
let mut final_query = Map::new();
508518
final_query.insert("bool".to_string(), json!({ "filter": updated_query }));
509519

0 commit comments

Comments
 (0)