Type Definition elastic::client::requests::document_update::UpdateRequestBuilder [] [src]

type UpdateRequestBuilder<TSender, TBody> = RequestBuilder<TSender, UpdateRequestInner<TBody>>;

An update document request builder that can be configured before sending.

Call Client.document_update to get an UpdateRequestBuilder. The send method will either send the request synchronously or asynchronously, depending on the Client it was created from.

Methods

impl<TSender, TBody> UpdateRequestBuilder<TSender, TBody> where
    TSender: Sender
[src]

Builder methods

Configure an UpdateRequestBuilder before sending it.

[src]

Set the type for the update request.

[src]

Update the source using a document.

Examples

Update a DocumentType called MyType with an id of 1 using a new document value:

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .doc(new_doc)
                     .send();

The document doesn't necessarily need to be of the same type so partial updates can be made. Be careful though because this can lead to unexpected results or runtime errors if the document types don't align:

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .doc(json!({
                         "title": "New Title"
                     }))
                     .send();

[src]

Update the source using an inline script.

Examples

Update the title property of a document using a script:

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .script(r#"ctx._source.title = "New Title""#)
                     .send();

Update the title property of a document using a parameterised script:

let script = ScriptBuilder::new("ctx._source.title = params.newTitle")
    .param("newTitle", "New Title");

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .script(script)
                     .send()?;

assert!(response.updated());

[src]

Update the source using a script configured by a fluent closure API.

The fluent API can be more ergonomic to work with than constructing builders directly. Susequent calls to script will override any previous script properties.

Examples

Update the title property of a document using a parameterised script:

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .script_fluent("ctx._source.title = params.newTitle", |script| script
                        .param("newTitle", "New Title"))
                     .send()?;

assert!(response.updated());

Script parameters can also be strongly typed, so long as they implement the Serialize trait. If the parameters don't serialize to an object then Elasticsearch will fail to parse them:

#[derive(Serialize)]
struct MyParams {
    title: &'static str
}

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .script_fluent("ctx._source.title = params.title", |script| script
                        .params(MyParams {
                            title: "New Title",
                        }))
                     .send()?;

assert!(response.updated());

impl<TBody> UpdateRequestBuilder<SyncSender, TBody> where
    TBody: Serialize
[src]

[src]

Send an UpdateRequestBuilder synchronously using a SyncClient.

This will block the current thread until a response arrives and is deserialised.

Examples

Update a document from an index called myindex with an id of 1:

let response = client.document_update::<MyType>(index("myindex"), id(1))
                     .doc(new_doc)
                     .send()?;

assert!(response.updated());

impl<TBody> UpdateRequestBuilder<AsyncSender, TBody> where
    TBody: Serialize + Send + 'static, 
[src]

[src]

Send an UpdateRequestBuilder asynchronously using an AsyncClient.

This will return a future that will resolve to the deserialised update document response.

Examples

Update a document from an index called myindex with an id of 1:

let future = client.document_update::<Value>(index("myindex"), id(1))
                   .doc(new_doc)
                   .send();

future.and_then(|response| {
    assert!(response.updated());

    Ok(())
});