Skip to content
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

[BUG] BulkParts is not convinient #93

Open
GopherJ opened this issue May 3, 2020 · 4 comments
Open

[BUG] BulkParts is not convinient #93

GopherJ opened this issue May 3, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@GopherJ
Copy link

GopherJ commented May 3, 2020

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when I'm not able to return back BulkParts from a function.

Often we just create Index by using part of my data but the following code won't compile

fn build_bulk<'a>(
    proximity_uuid: &'a str,
    alerts: Vec<Alert>,
) -> (BulkParts<'a>, Vec<JsonBody<Value>>) {
    let bulk_parts = BulkParts::Index(&format!("alerts.{}", proximity_uuid));
    let body: Vec<JsonBody<_>> = alerts
        .into_iter()
        .map(|alert| {
            vec![
                JsonBody::from(json!({"index": {"_id": Uuid::new_v4().to_simple().to_string() }})),
                JsonBody::from(json!(alert)),
            ]
        })
        .flatten()
        .collect();

    (bulk_parts, body)
}

Describe the solution you'd like
A clear and concise description of what you want to happen.

Make it possible to return back a BulkParts from a function

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@GopherJ GopherJ added the enhancement New feature or request label May 3, 2020
@GopherJ
Copy link
Author

GopherJ commented May 3, 2020

It'll even cause problem when we would like to bring BulkParts into async move {}, I'm not sure about the advantage over String...

@russcam
Copy link
Contributor

russcam commented May 7, 2020

thanks for opening @GopherJ. I need to have a think about this some more, but String would probably make parts easier to work with.

By the way, for the index operation, you can leave the "_id" blank if you don't care about the value assigned. Elasticsearch will generate an id for you in this scenario and indexing will be faster, because Elasticsearch no longer needs to check if there is an existing document with the provided id.

@GopherJ
Copy link
Author

GopherJ commented May 7, 2020

@russcam

By the way, for the index operation, you can leave the "_id" blank if you don't care about the value assigned. Elasticsearch will generate an id for you in this scenario and indexing will be faster, because Elasticsearch no longer needs to check if there is an existing document with the provided id.

cool I 'll adjust my code thanks for the info.

thanks for opening @GopherJ. I need to have a think about this some more, but String would probably make parts easier to work with.

yes I think maybe we need to pay attention to the usage of &'a str, if we will always write them manually I think it's ok but If we would like to create it through function it'll be hard because we will borrow a thing dropped after the function call.

But in my case finally I didn't return BulkParts from a function and I just return a String and then BulkParts::Index(&val) will compile fine.

@russcam
Copy link
Contributor

russcam commented May 7, 2020

Sorry, meant to say you can omit the "_id" field altogether :)

But in my case finally I didn't return BulkParts from a function and I just return a String and then BulkParts::Index(&val) will compile fine.

My thinking with the parts enums is that typically they would be constructed immediately next to or as part of the API call. Would like to have a think about it further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants