diff --git a/quickwit/quickwit-query/src/elastic_query_dsl/bool_query.rs b/quickwit/quickwit-query/src/elastic_query_dsl/bool_query.rs index 0b23b371151..01914223504 100644 --- a/quickwit/quickwit-query/src/elastic_query_dsl/bool_query.rs +++ b/quickwit/quickwit-query/src/elastic_query_dsl/bool_query.rs @@ -19,7 +19,7 @@ use serde::Deserialize; use serde_with::formats::PreferMany; -use serde_with::{serde_as, OneOrMany}; +use serde_with::{serde_as, DefaultOnNull, OneOrMany}; use crate::elastic_query_dsl::{ConvertableToQueryAst, ElasticQueryDslInner}; use crate::not_nan_f32::NotNaNf32; @@ -32,16 +32,16 @@ use crate::query_ast::{self, QueryAst}; #[derive(Deserialize, Debug, PartialEq, Eq, Clone)] #[serde(deny_unknown_fields)] pub struct BoolQuery { - #[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")] + #[serde_as(deserialize_as = "DefaultOnNull>")] #[serde(default)] must: Vec, - #[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")] + #[serde_as(deserialize_as = "DefaultOnNull>")] #[serde(default)] must_not: Vec, - #[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")] + #[serde_as(deserialize_as = "DefaultOnNull>")] #[serde(default)] should: Vec, - #[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")] + #[serde_as(deserialize_as = "DefaultOnNull>")] #[serde(default)] filter: Vec, #[serde(default)] @@ -133,4 +133,26 @@ mod tests { } ); } + + #[test] + fn test_dsl_query_with_null_values() { + let bool_query_json = r#"{ + "must": null, + "must_not": null, + "should": null, + "filter": null, + "boost": null + }"#; + let bool_query: BoolQuery = serde_json::from_str(bool_query_json).unwrap(); + assert_eq!( + &bool_query, + &BoolQuery { + must: Vec::new(), + must_not: Vec::new(), + should: Vec::new(), + filter: Vec::new(), + boost: None, + } + ); + } } diff --git a/quickwit/rest-api-tests/scenarii/es_compatibility/0009-bool_query.yaml b/quickwit/rest-api-tests/scenarii/es_compatibility/0009-bool_query.yaml index 6be510d8e95..a7db3d90c56 100644 --- a/quickwit/rest-api-tests/scenarii/es_compatibility/0009-bool_query.yaml +++ b/quickwit/rest-api-tests/scenarii/es_compatibility/0009-bool_query.yaml @@ -105,4 +105,19 @@ expected: hits: total: value: 100 +--- +# Support null values +json: + query: + bool: + must: null + must_not: null + should: null + filter: null + boost: null +expected: + hits: + total: + value: 100 +