Skip to content

Elasticsearch, typed, for Rust

A client generated from Elasticsearch's own specification, so every request and response is a Rust type. Typed AI search, a document layer for your own types, and a way out wherever the types don't reach yet.
crates/oxsearch/examples/quickstart.rs
use oxsearch::document::{Document, Indexes};
use oxsearch::transport_reqwest::ReqwestTransport;
use oxsearch::{Client, Refresh};
use serde::{Deserialize, Serialize};
#[derive(Document, Serialize, Deserialize, Debug)]
#[index("quickstart-passages")]
struct Passage {
#[semantic_text]
text: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let client = Client::new(ReqwestTransport::new("http://localhost:9200")?);
let passages = client.index::<Passage>().refresh(Refresh::WaitFor);
let _ = passages.ensure_mapping().await?;
passages
.put(&Passage {
text: "HNSW graphs find nearest neighbours fast.".into(),
})
.await?;
passages
.put(&Passage {
text: "Replicas keep copies of shards on other nodes.".into(),
})
.await?;
for hit in passages
.search(Passage::TEXT.semantic("how do vector indexes work?"))
.await?
{
println!("{:.2} {:?}", hit.score.unwrap_or_default(), hit.source);
}
Ok(())
}

A struct is the document type. #[derive(Document)] builds its index mapping, semantic_text included, and gives it field handles: Passage::TEXT.semantic(…) is a semantic query on that field, and a field of the wrong type offers no such query. The search reads hits back as Passage.

Generated from the specification

Every type and endpoint comes from the Elasticsearch specification, pinned to one commit, and is never edited by hand. CI generates the code again and fails if it differs. Each area is its own crate behind a feature, so an application compiles only what it uses.

Typed AI search

Retrievers, semantic, knn and sparse_vector queries, semantic_text mappings and the inference API, as types. Where the cluster’s license doesn’t include server-side fusion, oxsearch::fusion fuses on the client.

A way out everywhere

Your own endpoints go through the same client. A query, retriever or value the types don’t know is a Raw variant, and Client::send_raw sends anything at all.

Tested against Elasticsearch

Each endpoint is checked against the specification’s own examples, and an area counts as supported only once the integration tests run it against Elasticsearch, on the Basic license and a trial.