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]
TSender: Sender,
Builder methods
Configure an UpdateRequestBuilder
before sending it.
pub fn ty<I>(self, ty: I) -> Self where
I: Into<Type<'static>>,
[src]
I: Into<Type<'static>>,
Set the type for the update request.
pub fn doc<TDocument>(
self,
doc: TDocument
) -> UpdateRequestBuilder<TSender, Doc<TDocument>> where
TDocument: Serialize + DocumentType,
[src]
self,
doc: TDocument
) -> UpdateRequestBuilder<TSender, Doc<TDocument>> where
TDocument: Serialize + DocumentType,
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();
pub fn script<TScript, TParams>(
self,
builder: TScript
) -> UpdateRequestBuilder<TSender, Script<TParams>> where
TScript: Into<ScriptBuilder<TParams>>,
[src]
self,
builder: TScript
) -> UpdateRequestBuilder<TSender, Script<TParams>> where
TScript: Into<ScriptBuilder<TParams>>,
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());
pub fn script_fluent<TScript, TBuilder, TParams>(
self,
source: TScript,
builder: TBuilder
) -> UpdateRequestBuilder<TSender, Script<TParams>> where
TScript: ToString,
TBuilder: Fn(ScriptBuilder<Map<String, Value>>) -> ScriptBuilder<TParams>,
[src]
self,
source: TScript,
builder: TBuilder
) -> UpdateRequestBuilder<TSender, Script<TParams>> where
TScript: ToString,
TBuilder: Fn(ScriptBuilder<Map<String, Value>>) -> ScriptBuilder<TParams>,
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]
TBody: Serialize,
pub fn send(self) -> Result<UpdateResponse, Error>
[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]
TBody: Serialize + Send + 'static,
pub fn send(self) -> Pending
[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(()) });