opensearch_dsl/lib.rs
1//! # OpenSearch DSL for Rust
2//!
3//! A high-level, strongly typed Domain Specific Language (DSL) for building OpenSearch queries in Rust.
4//! This library provides a complete mapping to the OpenSearch Query DSL with compile-time type safety.
5//!
6//! *Based on the excellent [elasticsearch-dsl-rs](https://github.com/vinted/elasticsearch-dsl-rs)
7//! project, adapted for OpenSearch.*
8//!
9//! ## Features
10//!
11//! - **🔒 Type Safety**: Strongly typed queries, aggregations, and responses with compile-time validation
12//! - **🎯 Complete Coverage**: Full support for OpenSearch Query DSL including complex nested queries
13//! - **📊 Rich Aggregations**: Support for all aggregation types with proper result parsing
14//! - **🧩 Composable**: Build complex queries by composing smaller query components
15//! - **⚡ Zero-Cost Abstractions**: Compiles to efficient JSON with no runtime overhead
16//! - **🔌 Client Agnostic**: Works with any HTTP client, not tied to specific OpenSearch client libraries
17//! - **📝 Auto-Generated JSON**: Automatically produces valid OpenSearch JSON from Rust code
18//! - **🎨 Fluent API**: Chainable method calls for intuitive query building
19//!
20//! ## Installation
21//!
22//! Add to your `Cargo.toml`:
23//!
24//! ```toml
25//! [dependencies]
26//! opensearch-dsl = "0.3"
27//! ```
28//!
29//! ## Quick Start
30//!
31//! ### Basic Search Query
32//!
33//! ```rust
34//! use opensearch_dsl::*;
35//!
36//! let search = Search::new()
37//! .source(false)
38//! .from(0)
39//! .size(10)
40//! .query(Query::match_all())
41//! .sort(vec![Sort::field("timestamp").desc()]);
42//!
43//! // Generates valid OpenSearch JSON
44//! let json = serde_json::to_string(&search)?;
45//! ```
46//!
47//! ### Complex Boolean Query
48//!
49//! ```rust
50//! let search = Search::new()
51//! .query(
52//! Query::bool()
53//! .must(vec![
54//! Query::match_("title", "OpenSearch"),
55//! Query::range("date").gte("2023-01-01")
56//! ])
57//! .should(vec![
58//! Query::term("category", "tutorial"),
59//! Query::term("featured", true)
60//! ])
61//! .filter(vec![
62//! Query::term("status", "published")
63//! ])
64//! .minimum_should_match(1)
65//! );
66//! ```
67//!
68//! ### Aggregations
69//!
70//! ```rust
71//! let search = Search::new()
72//! .size(0)
73//! .aggregations(vec![
74//! ("categories", Aggregation::terms("category")),
75//! ("monthly_sales",
76//! Aggregation::date_histogram("date", "month")
77//! .sub_aggregation("total_revenue", Aggregation::sum("price"))
78//! )
79//! ]);
80//! ```
81//!
82//! ## Module Organization
83//!
84//! - [`search`] - Search queries and request building
85//! - [`query`] - All query types (term, match, bool, etc.)
86//! - [`aggregation`] - Aggregation types and builders
87//! - [`sort`] - Sorting options and configurations
88//! - [`types`] - Common types and utilities
89//!
90//! ## Integration with OpenSearch Client
91//!
92//! This DSL works seamlessly with the opensearch-client:
93//!
94//! ```rust
95//! use opensearch_client::*;
96//! use opensearch_dsl::*;
97//!
98//! let client = OsClient::new(/* configuration */);
99//! let search = Search::new().query(Query::match_("title", "rust"));
100//! let response = client.search(&search).index("articles").await?;
101//! ```
102//!
103//! ## Examples
104//!
105//! For comprehensive examples including e-commerce search, log analytics, and time series analysis,
106//! see the [examples directory](https://github.com/aparo/opensearch-client-rs/tree/main/examples).
107//!
108//! use opensearch_dsl::*;
109//!
110//! fn main() {
111//! let query = Search::new()
112//! .source(false)
113//! .stats("statistics")
114//! .from(0)
115//! .size(30)
116//! .query(
117//! Query::bool()
118//! .must(Query::multi_match(
119//! ["title", "description"],
120//! "you know, for search",
121//! ))
122//! .filter(Query::terms("tags", ["opensearch"]))
123//! .should(Query::term("verified", true).boost(10)),
124//! )
125//! .aggregate(
126//! "country_ids",
127//! Aggregation::terms("country_id")
128//! .aggregate("catalog_ids", Aggregation::terms("catalog_id"))
129//! .aggregate("company_ids", Aggregation::terms("company_id"))
130//! .aggregate(
131//! "top1",
132//! Aggregation::top_hits()
133//! .size(1)
134//! .sort(FieldSort::ascending("user_id")),
135//! ),
136//! )
137//! .rescore(Rescore::new(Query::term("field", 1)).query_weight(1.2));
138//! }
139//! ```
140//!
141//! See examples for more.
142//!
143//! #### License
144//!
145//! <sup>
146//! Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
147//! 2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
148//! </sup>
149#![doc(
150 html_logo_url = "https://play-lh.googleusercontent.com/VvtT2Dvf_oOC3DL4c2i5hfNvwIqzdU2apScRMlmeRW10Yf-vJXnXqAjdNWE9KW5YvK0"
151)]
152#![deny(
153 bad_style,
154 dead_code,
155 deprecated,
156 improper_ctypes,
157 missing_debug_implementations,
158 missing_docs,
159 non_shorthand_field_patterns,
160 no_mangle_generic_items,
161 overflowing_literals,
162 path_statements,
163 patterns_in_fns_without_body,
164 // private_in_public,
165 trivial_casts,
166 trivial_numeric_casts,
167 unconditional_recursion,
168 unknown_lints,
169 unreachable_code,
170 unreachable_pub,
171 unused,
172 unused_allocation,
173 unused_comparisons,
174 unused_extern_crates,
175 unused_import_braces,
176 unused_mut,
177 unused_parens,
178 unused_qualifications,
179 unused_results,
180 warnings,
181 while_true
182)]
183#![allow(ambiguous_glob_reexports)]
184
185#[cfg(test)]
186#[macro_use]
187extern crate pretty_assertions;
188
189#[macro_use]
190extern crate serde;
191
192#[cfg(test)]
193#[macro_use]
194extern crate serde_json;
195
196// Macro modules
197#[macro_use]
198mod macros;
199mod types;
200
201// Crate modules
202#[macro_use]
203pub mod util;
204pub use self::types::*;
205
206// Public modules
207pub mod analyze;
208pub mod search;
209
210// Public re-exports
211pub use self::{analyze::*, search::*};