#elasticsearch #search


A modular sync and async client for the Elasticsearch REST API

31 releases

0.20.10 May 7, 2018
0.20.9 Feb 6, 2018
0.20.8 Dec 17, 2017
0.20.6 Nov 30, 2017
0.10.0 Mar 20, 2017

#74 in Database interfaces

Download history 74/week @ 2018-10-26 326/week @ 2018-11-02 342/week @ 2018-11-09 525/week @ 2018-11-16 230/week @ 2018-11-23 325/week @ 2018-11-30 405/week @ 2018-12-07 236/week @ 2018-12-14 145/week @ 2018-12-21 125/week @ 2018-12-28 44/week @ 2019-01-04 203/week @ 2019-01-11 156/week @ 2019-01-18

1,067 downloads per month
Used in 1 crate



elastic Latest Version Gitter

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

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


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.


Add elastic to your Cargo.toml:

elastic = "*"
elastic_derive = "*"
serde_json = "*"

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 = SyncClientBuilder::new().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: i32,
	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.


Licensed under either of these:


~394K SLoC