elasticsearch_dsl/search/queries/custom/
json_query.rs1use crate::search::*;
2use crate::util::*;
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
16pub struct JsonQuery(serde_json::Value);
17
18impl Query {
19 pub fn json(query: serde_json::Value) -> JsonQuery {
23 JsonQuery(query)
24 }
25}
26
27impl From<serde_json::Value> for Query {
28 fn from(value: serde_json::Value) -> Self {
29 Self::Json(JsonQuery(value))
30 }
31}
32
33impl From<serde_json::Value> for JsonQuery {
34 fn from(value: serde_json::Value) -> Self {
35 Self(value)
36 }
37}
38
39impl ShouldSkip for JsonQuery {
40 fn should_skip(&self) -> bool {
41 !self.0.is_object()
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn serialization() {
51 assert_serialize_query(
52 Query::json(json!({ "term": { "user": "username" } })),
53 json!({ "term": { "user": "username" } }),
54 );
55 }
56}