Crate elastic_reqwest [−] [src]
Elasticsearch REST API Client
A lightweight implementation of the Elasticsearch API based on the
reqwest
HTTP client.
Each API endpoint is represented as its own function, so each possible http route gets its own function. This library makes very few assumptions, leaving it up to you to decide what to invest your precious CPU cycles into.
The entire API is generated from the official Elasticsearch spec, so it's always current.
Supported Versions
elastic_types |
Elasticsearch |
---|---|
0.x |
5.x |
Usage
This crate is on crates.io.
To get started, add elastic_reqwest
and reqwest
to your Cargo.toml
:
[dependencies] elastic_requests = "*" elastic_reqwest = "*" reqwest = "*"
For Windows
, you may need to exclude openssl
or the build can fail:
[dependencies] elastic_requests = "*" elastic_reqwest = { version = "*", default-features = false }
Then reference in your crate root:
extern crate elastic_requests as req; extern crate elastic_reqwest as cli;
Minimal Example
Ping the availability of your cluster:
//HTTP HEAD / use cli::ElasticClient; use req::PingRequest; let (client, params) = cli::default().unwrap(); client.elastic_req(¶ms, PingRequest::new()).unwrap();
Search Request with Url Param
Execute a search query with a url parameter:
//HTTP GET /myindex/mytype/_search?q='my string' extern crate reqwest; extern crate elastic_requests as req; extern crate elastic_reqwest as cli; use cli::{ ElasticClient, RequestParams }; use req::SimpleSearchRequest; let (client, _) = cli::default().unwrap(); let params = RequestParams::default() .url_params(vec![ ("q", "'my string'".to_owned()), ("pretty", "true".to_owned()) ]); let search = SimpleSearchRequest::for_index_ty( "myindex", "mytype" ); client.elastic_req(¶ms, search).unwrap();
Search Request with Json
Using the json_str
crate, you can execute
queries using pure json:
//HTTP POST /myindex/mytype/_search #[macro_use] extern crate json_str; extern crate elastic_requests as req; extern crate elastic_reqwest as cli; use cli::ElasticClient; use req::SearchRequest; let (client, params) = cli::default().unwrap(); let search = SearchRequest::for_index_ty( "myindex", "mytype", json_str!({ query: { filtered: { query: { match_all: {} }, filter: { geo_distance: { distance: "20km", location: { lat: 37.776, lon: -122.41 } } } } } }) ); client.elastic_req(¶ms, search).unwrap();
See more examples.
See Also
rs-es
An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL.
elastic_types
A library that implements the core datatypes in Elasticsearch documents and automatically generates a json mapping from your Rust structures.
json_str
A library for generating minified json strings from Rust syntax.
Links
Structs
RequestParams |
Misc parameters for any request. |
Traits
ElasticClient |
Represents a client that can send Elasticsearch requests. |
Functions
default |
Get a default |