#dsl #elasticsearch #elastic #query

elastic-query-builder

ElasticSearch Query Builder

37 releases

0.1.36 Feb 1, 2024
0.1.35 Sep 20, 2023
0.1.33 Aug 24, 2023
0.1.32 Feb 24, 2023
0.1.3 Feb 25, 2022

#359 in Database interfaces

Download history 65/week @ 2023-10-31 9/week @ 2023-11-07 9/week @ 2023-11-14 50/week @ 2023-11-21 153/week @ 2023-11-28 80/week @ 2023-12-05 43/week @ 2023-12-12 10/week @ 2023-12-19 115/week @ 2023-12-26 7/week @ 2024-01-02 9/week @ 2024-01-09 12/week @ 2024-01-16 17/week @ 2024-01-23 198/week @ 2024-01-30 51/week @ 2024-02-06 257/week @ 2024-02-13

525 downloads per month
Used in 2 crates (via uiuifree-elastic)

MIT license

78KB
2.5K SLoC

ElasticQueryBuilder

Crates.io GitHub

ElasticQueryBuilder is a query builder designed to easily build ElasticSearch related DSLs.

install

# Cargo.toml
[dependencies]
elastic-query-builder ="0.1"

Futures

  • Mapping
  • DML Query
  • Aggregation

Mapping

fn main() {
    let mut mapping = MappingBuilder::new();
    mapping
        .add_property("title", KeywordFieldType::new())
        .add_property("content", TextFieldType::new());
    assert_eq!(
        mapping.build().to_string(),
        r#"{"mappings":{"properties":{"content":{"type":"text"},"title":{"type":"keyword"}}}}"#
    );
}

DML Query

Build Json Query

fn main() {
    let mut query = QueryBuilder::new();
    query.set_query(MatchQuery::new("field", "value"));
    query.set_from(10);
    query.set_size(100);
    let value_json = query.build();
}

Providing Query

  • bool_query
  • exists_query
  • geo_distance_query
  • match_all_query
  • match_query
  • multi_match_query
  • nested
  • range_query
  • script_query
  • script_score_query
  • term_query
  • terms_query
  • wildcard_query

BoolQuery Example

fn main() {
    let mut query = QueryBuilder::new();
    let mut bool = BoolQuery::new();
    bool.add_must(MatchQuery::new("field1", "value"));
    bool.add_must_not(MatchQuery::new("field2", "value"));
    bool.add_should(MatchQuery::new("field3", "value"));
    query.set_query(bool);
}

Nested Example

fn main() {
    let mut query = QueryBuilder::new();
    let nested = NestedQuery::new("locations", MatchQuery::new("locations.country", "JP"));
    query.set_query(nested);
}

Dependencies

~0.7–1.5MB
~34K SLoC