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_reqwest = "*"
reqwest = "*"

Then reference in your crate root:

extern crate elastic_reqwest as cli;

Minimal Example

Ping the availability of your cluster:

//HTTP HEAD /

use cli::ElasticClient;
use cli::req::PingRequest;

let (client, params) = cli::default().unwrap();

client.elastic_req(&params, 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_reqwest as cli;
use cli::{ ElasticClient, RequestParams };
use cli::req::SimpleSearchRequest;

let (client, _) = cli::default().unwrap();

let params = RequestParams::default()
    .url_param("pretty", true)
    .url_param("q", "*");

let search = SimpleSearchRequest::for_index_ty(
    "myindex", "mytype"
);

client.elastic_req(&params, 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_reqwest as cli;
use cli::ElasticClient;
use cli::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(&params, search).unwrap();

See more examples.

See Also

elastic

A higher-level Elasticsearch client that uses elastic_reqwest as its HTTP layer.

rs-es

An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL.

json_str

A library for generating minified json strings from Rust syntax.

Links

Modules

req

Request types.

Structs

RequestParams

Misc parameters for any request.

Traits

ElasticClient

Represents a client that can send Elasticsearch requests.

Functions

default

Get a default Client and RequestParams.