Crates.io | elastic-query-builder |
lib.rs | elastic-query-builder |
version | 0.1.39 |
source | src |
created_at | 2022-02-24 13:09:40.355405 |
updated_at | 2024-10-16 01:00:01.021514 |
description | ElasticSearch Query Builder |
homepage | |
repository | https://github.com/uiuifree/elastic-query-builder |
max_upload_size | |
id | 538507 |
size | 82,207 |
ElasticQueryBuilder is a query builder designed to easily build ElasticSearch related DSLs.
# Cargo.toml
[dependencies]
elastic-query-builder ="0.1"
Mapping
DML Query
Aggregation
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"}}}}"#
);
}
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();
}
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
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);
}
fn main() {
let mut query = QueryBuilder::new();
let nested = NestedQuery::new("locations", MatchQuery::new("locations.country", "JP"));
query.set_query(nested);
}