-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for _source on update requests #381
Add support for _source on update requests #381
Conversation
@@ -13,6 +16,14 @@ use crate::{ | |||
}, | |||
}; | |||
|
|||
#[derive(Deserialize, Debug)] | |||
struct UpdatedSource<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also add found: bool
, sequence_number: Option<i32>
, and primary_term: Option<i32>
to this if we want. I felt like they were a little superfluous...
Oh also, should I add a mechanism to specify |
Thanks for the PR @mwilliammyers! Hmm, it keeping with the rest of the crate style I think we would want to make #[derive(Deserialize, ElasticType, Debug)]
struct User {
#[elastic(id)]
id: String,
name: String,
}
#[derive(Serialize, ElasticType, Debug)]
struct UpdateUser {
#[elastic(id)]
id: String,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
}
let response = client
.document::<UpdateUser>()
.update(1)
.script(r#"ctx._source.name = "Updated Name""#)
.params_fluent(|params| params.url_param("_source", true))
.send()?;
dbg!(&response.into_document::<User>()); where What if we did something like: let response = client
.document::<User>()
.update(1)
.script(r#"ctx._source.name = "Updated Name""#)
.source::<UpdateUser>()
.send()?; So that we effectively have What do you think? |
That makes sense. I did something similar for I don't think it really resolves the footgun problem because I expose let response = client
.document::<UpdateUser>()
.update(1)
.script(r#"ctx._source.name = "Updated Name""#)
.source::<User>()
.send()?; I didn't notice this issue because I have to manually resolve the index for each document via the This is definitely a separate issue, and I will open one when I have more concrete ideas, but I wonder if we could/should expand the "index name from a method" mechanism to be able to pass in parameters (e.g. the |
This is a more ergonomic way to include the updated doc in the response. Also: - Add integration test - Add example - Update docs Close elastic-rs#381
@KodrAus I implemented it like you suggested I am going to wait to merge this until we decide what to do with #382. My vote is we do |
This is a more ergonomic way to include the updated doc in the response. Also: - Add integration test - Add example - Update docs Close elastic-rs#381
This will match upcoming changes for source filtering to the bulk API.
5abfa57
to
54b7f9b
Compare
Until I can figure out a better way to do #382, I propose we merge this. I will have to revisit this anyway to add support for passing in a |
In order to maintain backwards compatibility by not introducing a new generic parameter on
UpdateResponse
, I had to useserde_json::Value
as an intermediate value...If we are ok with not maintaining backwards compatibility I can update this PR and introduce a new generic parameter, which will result in something like this:
UpdateRequestBuilder<TSender, TBody, TDocument>
.As a result, as of right now, you use this like:
I am hoping to tackle
bulk
updates ASAP too...