Crate elastic_requests [] [src]

Elasticsearch Request Types

An implementation of the Elasticsearch REST API using strong types for endpoints.

The source is automatically generated from the official spec. A struct is provided for each endpoint that works with borrowed or owned data. There's also a more general HttpRequest type that all requests can be converted into.

Request types are generic over the body buffer, B. This gives you a lot of flexibility when designing APIs, but you should be careful to ensure the B is bound appropriately.

Supported Versions

elastic_requests Elasticsearch
0.x 5.x

Usage

All request types provide constructor functions of the form param_1_param_2_param_n:

let req = SearchRequest::for_index_ty(
    "test_index",
    "test_ty",
    "{'query': { 'match_all': {}}}"
);

assert_eq!("/test_index/test_ty/_search", req.url.as_ref());

Or new if the endpoint takes no parameters:

let req = PingRequest::new();

assert_eq!("/", req.url.as_ref());

Parameters can be borrowed or owned string values:

let req = SearchRequest::for_index(
    "test_index".to_string(),
    "{'query': { 'match_all': {}}}"
);

assert_eq!("/test_index/_search", req.url.as_ref());

All request types can be converted into a more general HttpRequest. In this example, takes_req accepts anything that can be converted into a HttpRequest where the body buffer is AsRef<[u8]>:

fn takes_req<'a, I: Into<HttpRequest<'a, B>>, B: AsRef<[u8]>>(req: I) {
    let req = req.into();
    let body = req.body.as_ref();

    // do something with the request
}

takes_req(PingRequest::new());
takes_req(SearchRequest::for_index("test_index", empty_body()));

Why are these docs useless?

This library is automatically generated, so there's a lot more work to do to get the documentation up to scratch.

Links

Reexports

pub use self::params::*;
pub use self::endpoints::*;

Modules

endpoints

REST API endpoints.

params

Common url params like Id and Index.

Structs

HttpRequest

A general request type that all endpoints can be converted into.

Url

A wrapper around an owned or borrowed url.

Enums

HttpMethod

A standard HTTP verb.

Functions

empty_body

A convenience method for a default, empty body. This method doesn't allocate.

Type Definitions

DefaultBody

A default body type.