1#![allow(unused_imports)]
67#![allow(clippy::too_many_arguments)]
68
69pub extern crate opensearch_dsl;
70extern crate reqwest;
71extern crate serde;
72extern crate serde_json;
73extern crate serde_repr;
74extern crate url;
75use std::sync::OnceLock;
76
77pub use opensearch_dsl as dsl;
82
83mod bulk;
84mod bulker;
85
86pub use bulk::*;
87pub use bulker::*;
88
89#[cfg(feature = "asynchronous_search")]
91pub mod asynchronous_search;
92
93#[cfg(feature = "cat")]
95pub mod cat;
96
97#[cfg(feature = "cluster")]
99pub mod cluster;
100
101pub mod common;
103
104pub mod core;
106
107#[cfg(feature = "dangling_indices")]
109pub mod dangling_indices;
110#[cfg(feature = "indices")]
111pub mod indices;
112#[cfg(feature = "ingest")]
113pub mod ingest;
114#[cfg(feature = "insights")]
115pub mod insights;
116#[cfg(feature = "ism")]
117pub mod ism;
118#[cfg(feature = "knn")]
119pub mod knn;
120#[cfg(feature = "ml")]
121pub mod ml;
122#[cfg(feature = "nodes")]
123pub mod nodes;
124#[cfg(feature = "notifications")]
125pub mod notifications;
126#[cfg(feature = "observability")]
127pub mod observability;
128#[cfg(feature = "ppl")]
129pub mod ppl;
130pub mod query;
132#[cfg(feature = "remote_store")]
133pub mod remote_store;
134#[cfg(feature = "replication")]
135pub mod replication;
136#[cfg(feature = "rollups")]
137pub mod rollups;
138pub mod search;
139#[cfg(feature = "security")]
140pub mod security;
141#[cfg(feature = "snapshot")]
142pub mod snapshot;
143#[cfg(feature = "sql")]
144pub mod sql;
145pub mod tasks;
147#[cfg(feature = "transforms")]
148pub mod transforms;
149
150mod client;
151#[cfg(feature = "tools")]
152pub mod tools;
153
154pub use client::configuration::Configuration;
155pub use client::configuration::ConfigurationBuilder;
156pub use client::Error;
157pub use client::OsClient;
158pub use client::ResponseContent;
159
160mod document;
161pub use document::*;
162pub use opensearch_macro::OpenSearch;
163static OPENSEARCH: OnceLock<OsClient> = OnceLock::new();
164
165pub fn set_opensearch(client: OsClient) -> Result<(), OsClient> {
166 OPENSEARCH
167 .set(client)
168 .map_err(|_| OsClient::from_environment().unwrap())
169}
170
171pub fn get_opensearch() -> &'static OsClient {
172 OPENSEARCH.get_or_init(|| {
173 OsClient::from_environment().expect("Failed to load OPENSEARCH configuration")
174 })
175}
176
177#[cfg(test)]
178mod tests {
179
180 use std::path::PathBuf;
181
182 use serde::de::DeserializeOwned;
183
184 use super::*;
185 fn load_entity<T: DeserializeOwned>(name: &str) -> T {
186 let filename = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("tests/base/{name}"));
187 let text = std::fs::read_to_string(filename).unwrap();
188 serde_json::from_str(&text).unwrap()
189 }
190
191 #[test]
192 fn test_document_delete_response() {
193 let decoded: crate::common::DocumentDeleteResponse =
194 load_entity("document_delete.response.json");
195 assert_eq!(decoded.id, String::from("MzcIJX8BA7mbufL6DOwl"));
196 }
197}