elastic / elasticsearch-rs

Official Elasticsearch Rust Client
https://www.elastic.co/guide/en/elasticsearch/client/rust-api/current/index.html
Apache License 2.0
705 stars 72 forks source link

[ENHANCEMENT] Allow str, bytes and Serialize request bodies #31

Closed russcam closed 4 years ago

russcam commented 4 years ago

The current body associated fn on each builder struct expects a T that implements the Serialize trait. For example, for Search

pub fn body<T>(self, body: T) -> Search<'a, T>
    where
        T: Serialize,
{
    // ...
}

The body T is then passed to reqwest's json() fn to serialize as JSON.

Both String and Vec<u8>, and their reference/slice counterparts have Serialize impls, but the resulting request body is unexpected/not that useful; For String, the body will be a literal string value enclosed in double quotes, whilst Vec<u8> will be a JSON array of numbers.

What is probably more useful is to allow a consumer to pass a JSON string literal or JSON bytes to the body method, and write these using reqwest's body() fn.

russcam commented 4 years ago

tangentially related to this is the ability to accept a body that will serialize to newline delimited JSON (ndjson) for the following APIs

russcam commented 4 years ago

opened #32 to address