#elasticsearch #search


A modular sync and async client for the Elasticsearch REST API

36 releases

0.21.0-pre.5 Jul 7, 2019
0.21.0-pre.2 Feb 23, 2019
0.20.10 May 7, 2018
0.20.9 Feb 6, 2018
0.10.0 Mar 20, 2017

#630 in Database interfaces

Download history 86/week @ 2023-01-23 410/week @ 2023-01-30 64/week @ 2023-02-06 152/week @ 2023-02-13 98/week @ 2023-02-20 20/week @ 2023-02-27 230/week @ 2023-03-06 165/week @ 2023-03-13 27/week @ 2023-03-20 38/week @ 2023-03-27 41/week @ 2023-04-03 69/week @ 2023-04-10 21/week @ 2023-04-17 52/week @ 2023-04-24 67/week @ 2023-05-01 102/week @ 2023-05-08

243 downloads per month
Used in 3 crates


28K SLoC

elastic Latest Version Gitter

elastic is an efficient, modular API client for Elasticsearch written in Rust. The API is targeting the Elastic Stack 7.x.

elastic provides strongly-typed documents and weakly-typed queries.

Quick reference:


This crate is still quite unstable and is likely to continue to churn breaking releases over the near future with not-so-detailed changelogs.

If you run into any problems upgrading in your own open source projects feel free to open up an issue and we'll give you a hand. The goal is definitely to offer a stable API eventually.

Build Status

Platform Channel Status (master)
Linux / OSX Stable/Nightly Build Status
Windows Nightly Build status


Version Docs
current (master) Documentation


Add elastic to your Cargo.toml:

elastic = "0.21.0-pre.5"
elastic_derive = "0.21.0-pre.5"
serde_json = "1"

Create a SyncClient and start making requests:

extern crate elastic_derive;
extern crate serde_json;
extern crate elastic;

use serde_json::Value;
use elastic::prelude::*;

// A reqwest HTTP client and default parameters.
// The builder includes the base node url (http://localhost:9200).
let client = SyncClient::builder().build()?;

let query = "some query string";

// A search request with a freeform body.
let res = client.search::<Value>()
                    "query": {
                        "query_string": {
                            "query": query

// Iterate through the hits in the response.
for hit in res.hits() {
    println!("{:?}", hit);

elastic also offers an AsyncClient for use with the tokio asynchronous io stack. See the examples folder for complete samples.

Building documents

Document mapping is derived at compile-time from your Plain Old Rust Structures. Just add a #[derive(ElasticType)] attribute:

#[derive(ElasticType, Serialize, Deserialize)]
struct MyDocument {
	pub id: String,
	pub title: String,
	pub timestamp: Date<DefaultDateMapping<EpochMillis>>,
	pub content: Text<DefaultTextMapping>,

And you can start using MyDocument in Client request methods.

See the docs for more details.


If you'd like to use a strongly-typed Query DSL builder see rs-es. This client does the hard work of providing an idiomatic Rust API for interacting with Elasticsearch. It has the advantage of letting you know your queries will parse at compile-time instead of runtime.


To provide a full-featured and efficient Elasticsearch client for Rust over asynchronous io. Rust gives us a lot of tools for building super-performant but highly accessible libraries, which we aim to continue. elastic is aimed at people who need to work with Elasticsearch and are considering using Rust, as well as users that are already using Rust. We want to offer a solution to interacting with Elasticsearch that's compelling from both within and outside the Rust ecosystem.

The REST API is covered by a simple inline JSON macro like serde_json's json! so it's always possible to build any query. This means you don't need to learn another API for interacting with Elasticsearch; queries mocked in Dev Tools could just be copy+pasted into your Rust source.

The core focus of this project is on strong typing over your document types and query responses in Elasticsearch, rather than trying to map the entire Query DSL.

Support for Elastic's plugin products, like watcher and graph could be added as feature-gated modules as necessary.


Licensed under either of these:


~685K SLoC