elasticsearch_dsl/search/queries/
match_all_query.rs

1use super::Query;
2use crate::util::*;
3
4/// The most simple query, which matches all documents, giving them all a
5/// `_score` of `1.0`.
6///
7/// To create match_all query:
8/// ```
9/// # use elasticsearch_dsl::queries::*;
10/// # use elasticsearch_dsl::queries::params::*;
11/// # let query =
12/// Query::match_all()
13///     .boost(2)
14///     .name("matches_everything");
15/// ```
16/// <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html>
17#[derive(Debug, Clone, PartialEq, Serialize, Default)]
18#[serde(remote = "Self")]
19pub struct MatchAllQuery {
20    #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
21    boost: Option<f32>,
22
23    #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
24    _name: Option<String>,
25}
26
27serialize_with_root!("match_all": MatchAllQuery);
28
29impl Query {
30    /// Creates an instance of [`MatchAllQuery`]
31    pub fn match_all() -> MatchAllQuery {
32        MatchAllQuery::default()
33    }
34}
35
36impl MatchAllQuery {
37    add_boost_and_name!();
38}
39
40impl ShouldSkip for MatchAllQuery {}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn serialization() {
48        assert_serialize_query(Query::match_all(), json!({ "match_all": {} }));
49
50        assert_serialize_query(
51            Query::match_all().boost(2).name("test"),
52            json!({ "match_all": { "boost": 2.0, "_name": "test" } }),
53        );
54    }
55}