Open t-smirnov opened 1 year ago
Not sure if you have any interest; but I'm working on something to address this: https://github.com/benfalk/elastic_lens/blob/master/examples/simple_search.rs
Here is an example of DSL so far:
use elastic_lens::{prelude::*, request::search::GeoPoint, response::SearchResults, Error};
use serde_json::Value;
// Getting the documents back as serde JSON
// The client will deserialize the `_source` to any type
// that implements for it. See `examples/inventory_item.rs`
// for an example.
pub async fn complex_search() -> Result<SearchResults<Value>, Error> {
let client = create_client()?;
let mut search = Search::default();
search.with(
field("server.location")
.within(500)
.miles()
.of(GeoPoint::new(12.2, 18.9)),
);
search.with(field("log.level").has_any_of(["error", "warning"]));
search.with(field("log.trace").exists());
search.with(if_any_match(|any| {
any.with(field("service").contains("backend-core"));
any.with(if_all_match(|all| {
all.with(field("service").contains("frontend-core"));
all.with(field("tags").has_any_of(["market-place", "registration"]));
}));
}));
Ok(client.search(&search).await?)
}
Is your feature request related to a problem? Please describe. Not a problem, actually, but I would be way more cool, sometimes, to use builder pattern to build queries. Like it was implemented in high-level ES client for dotnet. Example: https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.17/writing-queries.html
Describe the solution you'd like Usage of builder pattern, like in dotnet client:
Rust
Describe alternatives you've considered only using json! macro with the body.
Additional context some more complex query example.