Skip to content

Commit

Permalink
Support null values for ES bool query array fields. (#3876)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmassot authored Sep 26, 2023
1 parent 979e686 commit 1219e00
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
32 changes: 27 additions & 5 deletions quickwit/quickwit-query/src/elastic_query_dsl/bool_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<OneOrMany<_, PreferMany>>")]
#[serde(default)]
must: Vec<ElasticQueryDslInner>,
#[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")]
#[serde_as(deserialize_as = "DefaultOnNull<OneOrMany<_, PreferMany>>")]
#[serde(default)]
must_not: Vec<ElasticQueryDslInner>,
#[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")]
#[serde_as(deserialize_as = "DefaultOnNull<OneOrMany<_, PreferMany>>")]
#[serde(default)]
should: Vec<ElasticQueryDslInner>,
#[serde_as(deserialize_as = "OneOrMany<_, PreferMany>")]
#[serde_as(deserialize_as = "DefaultOnNull<OneOrMany<_, PreferMany>>")]
#[serde(default)]
filter: Vec<ElasticQueryDslInner>,
#[serde(default)]
Expand Down Expand Up @@ -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,
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit 1219e00

Please sign in to comment.