elasticsearch_dsl/search/queries/specialized/wrapper_query.rs
1use crate::search::*;
2use crate::util::*;
3
4/// A query that accepts any other query as base64 encoded string.
5///
6/// This query is more useful in the context of the Java high-level REST client
7/// or transport client to also accept queries as json formatted string. In
8/// these cases queries can be specified as a json or yaml formatted string or
9/// as a query builder (which is a available in the Java high-level REST client).
10///
11/// To create wrapper query:
12/// ```
13/// # use elasticsearch_dsl::queries::*;
14/// # use elasticsearch_dsl::queries::params::*;
15/// # let query =
16/// Query::wrapper("eyJ0ZXJtIiA6IHsgInVzZXIuaWQiIDogImtpbWNoeSIgfX0=");
17/// ```
18/// <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wrapper-query.html>
19#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
20#[serde(remote = "Self")]
21pub struct WrapperQuery {
22 query: String,
23}
24
25impl Query {
26 /// Creates an instance of [`WrapperQuery`]
27 pub fn wrapper<S>(query: S) -> WrapperQuery
28 where
29 S: ToString,
30 {
31 WrapperQuery {
32 query: query.to_string(),
33 }
34 }
35}
36
37impl ShouldSkip for WrapperQuery {}
38
39serialize_with_root!("wrapper": WrapperQuery);
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn serialization() {
47 assert_serialize_query(
48 Query::wrapper("eyJ0ZXJtIiA6IHsgInVzZXIuaWQiIDogImtpbWNoeSIgfX0="),
49 json!({ "wrapper": { "query": "eyJ0ZXJtIiA6IHsgInVzZXIuaWQiIDogImtpbWNoeSIgfX0=" } }),
50 );
51 }
52}