elasticsearch_dsl/search/queries/span/
span_multi_query.rs

1use crate::util::*;
2use crate::{MultiTermQuery, Query};
3use serde::Serialize;
4
5/// The span_multi query allows you to wrap a `multi term query` (one of
6/// [`wildcard`](crate::WildcardQuery), [`fuzzy`](crate::FuzzyQuery),
7/// [`prefix`](crate::PrefixQuery), [`range`](crate::RangeQuery) or
8/// [`regexp`](crate::RegexpQuery) query) as a [`span query`](crate::SpanQuery), so it can be
9/// nested.
10///
11/// <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html>
12#[derive(Debug, Clone, PartialEq, Serialize)]
13#[serde(remote = "Self")]
14pub struct SpanMultiQuery {
15    r#match: Box<MultiTermQuery>,
16}
17
18impl ShouldSkip for SpanMultiQuery {}
19
20serialize_with_root!("span_multi": SpanMultiQuery);
21
22impl Query {
23    /// Creates an instance of [`SpanMultiQuery`]
24    #[allow(unused)]
25    pub fn span_multi<Q>(r#match: Q) -> SpanMultiQuery
26    where
27        Q: Into<MultiTermQuery>,
28    {
29        SpanMultiQuery {
30            r#match: Box::new(r#match.into()),
31        }
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn serialization() {
41        assert_serialize_query(
42            Query::span_multi(Query::prefix("test", "1234")),
43            json!({
44                "span_multi": {
45                    "match" : {
46                        "prefix": {
47                            "test": {
48                                "value": "1234"
49                            }
50                        }
51                    }
52                }
53            }),
54        );
55
56        assert_serialize_query(
57            Query::span_multi(Query::prefix("test", "1234")),
58            json!({
59                "span_multi": {
60                    "match" : {
61                        "prefix": {
62                            "test": {
63                                "value": "1234"
64                            }
65                        }
66                    }
67                }
68            }),
69        );
70    }
71}